Official guidelines for using functions newly adde

2019-09-04 18:05发布

问题:

I am writing a package that performs a statistical analysis while handling missing values. I am using the wonderful, life-changing function anyNA which was added sometime after 3.0 (commit). Another recently added function that people might want to use is OlsonNames.

So as I am using this function, my package won't work on older versions of R. I see four options for dealing with this.

  1. Make the whole package depend on R >= 3.1 in DESCRIPTION.

  2. Redefine the function in my source.

  3. Redefine the function if the user is using <3.1 and don't define it if they are using >= 3.1 or make the function check the version each time e.g.

    anyNA <- function(x)
      if(as.numeric(R.Version()$minor) > 3.1){
        return(anyNA(x)
      } else {
        return(any(is.NA(x))
      }
    }
    

    or

    if(as.numeric(R.Version()$minor) > 3.1){
      anyNA <- base::anyNA
    } else {
      anyNA <- function(x) any(is.na(x))
    }          
    

    I'm not even sure this second one would work in package source code.

  4. Rewrite my code using any(is.na(x)).

My concrete question is is there an official CRAN preference for one of these?

Failing that, are there good reasons to use one over the others? To my eyes they all have failings. 1) It seems unnecessary to require users have R >= 3.1 for the sake of a small function. 2) If I redefine the function, any improvements made to the function in R base won't get used in my package. 3) This mostly seems messy. But also, if the base R version of the function changes I might end up with hard to fix bugs that only occur in certain R versions. 4) Code readability is reduced.