Dependent and optional dependencies in R package CRAN path?

I would like to add a fallback dependency to my package. The problem is that I want to make this CRAN compatible and cannot figure out how to do it correctly.

In particular, I want to use data.table fread / fwrite. Other than that, I do not want to have a complete data.table dependency. If data.tablenot installed, my package should simply revert to using standard read.csvand write.csv.

I saw this similar thread: The correct way to handle additional package dependencies

and also used a technique similar to what @Hadley suggested in the comments:

req <- require(data.table)
if(req){ 
   data.table::fwrite(...)
 } else {
    write.csv(...)     

  }

This works, but when I start CHECK I get a NOTE:

'library' or 'require' call to ‘data.table’ in package code. Please use :: or requireNamespace() instead.

This means that I will not get it for CRAN supervisors ...

What is the right way to handle this?

+4
1

:

  • () require() requireNamespace()
  • TRUE .
  • :: .

( , ),

myreader <- function(file) {
    if (requireNamespace("data.table", quietly=TRUE)) {
       dat <- data.table::fread(file)
    } else {
       dat <- read.csv(file)
    }
    ## postprocess dat as needed
    dat
}

GitHub user:cran l=R yourTerm, . .

+7

Source: https://habr.com/ru/post/1692215/


All Articles