Search code examples
rnamespacesdevtoolsroxygen2

'data' is not an exported object from 'namespace:my_package'


I'm writing a function that uses an external data as follow:

First, it checks if the data is in the data/ folder, if it is not, it creates the data/ folder and then downloads the file from github;

If the data is already in the data/ folder, it reads it, and perform the calculations.

The question is, when I run:

devtools::check()

it returns:

Error: 'data' is not an exported object from 'namespace:my_package'

Should I manually put something on NAMESPACE?

An example:

my_function <- function(x){
if(file.exists("data/data.csv")){
    my_function_calculation(x = x)
  } else {
    print("Downloading source data...")
    require(RCurl)
    url_base <-
 getURL("https://raw.githubusercontent.com/my_repository/data.csv")
    dir.create(paste0(getwd(),"/data"))
    write.table(url_base,"data/data.csv", sep = ",", quote = FALSE)
    my_function_calculation(x = x)
  }
}

my_function_calculation <- function(x = x){
    data <- NULL
    data <- suppressMessages(fread("data/data.csv"))
    #Here, I use data...
    return(data)
}

Solution

  • It could not be the same in every case, but I've solved the problem by removing the data.R file on R/ folder.

    data.R is a file describing all data presented in the package. I had it since the previous version of my code, that had the data built in, not remote (to be downloaded). Removing the file solved my problem.

    Example of data.R:

    #' Name_of_the_data
    #'
    #' Description_of_the_Data
    #'
    #' @format A data frame with 10000 rows and 2 variables:
    #' \describe{
    #'   \item{Col1}{description of Col1}
    #'   \item{Col2}{description of Col2}
    #' }
    "data_name"