Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with "Warning: object 'xxx' is created by more than one data call"

When checking an R package, I got the warning

Warning: object 'xxx' is created by more than one data call

What causes this, and how can I fix it?

like image 382
Richie Cotton Avatar asked Nov 08 '15 05:11

Richie Cotton


1 Answers

This warning occurs when multiple RData files in the data directory of the package store a variable with the same name.

To reproduce, we create a package and save the cars dataset twice, to different files:

library(devtools)    
create("test")   
dir.create("test/data")    
save(cars, file = "test/data/cars1.RData")
save(cars, file = "test/data/cars2.RData")   
check("test")

The output from check includes these lines:

Found the following significant warnings: Warning: object 'cars' is created by more than one data call


If you receive this warning, you can find repeated variable names using:

rdata_files <- dir("test/data", full.names = TRUE, pattern = "\\.RData$")
var_names <- lapply(
  rdata_files,
  function(rdata_file)
  {
    e <- new.env()
    load(rdata_file, envir = e)
    ls(e)
  }
)

Reduce(intersect, var_names)
## [1] "cars"
like image 107
Richie Cotton Avatar answered Nov 15 '22 23:11

Richie Cotton