What bonehead wrote that code? (Answer: it was me)


#1

This is one of those things I want to laugh about with someone, but my spouse won’t get the humor.

I had to fix an error that was being thrown on Debian in the CRAN checks, but not any other OS. I thought that was weird. So I went to investigate and I found

mantel.test <- 
  function(x,byVar,row.scores=c("equal","midrank"),
                  col.scores=c("equal","midrank")){

    suppressWarnings(
      if(row.scores=="equal"){ row.scores <- seq(1,nrow(temp)) }
      # Midrank sores
      else if(row.scores=="midrank"){ row.scores <- midrank(temp) } 
    )

Naturally, my first thought is “what bonehead wrote that?” even though I’m the only person who has ever worked on this code base. And this is why I don’t like looking at code I wrote in 2008.


(If the error isn’t obvious to you, row.scores has a default length of 2. if only evaluates one logical value. The suppressWarnings silences the warning that passing a longer-than-one variable to if is a bad idea)