4

Similar Question

accessing sysdata.rda within package functions

Why This Similar Question Does Not Apply To Me

They were able to actually build it, and apparently it was a Github error for them (not related)

R VERSION

3.4.2 (I tried using 3.4.3 as well but the same problem occurred)

EDIT: I am on Windows 10

Context

I have fully read the following tutorial on R packages and how to include .Rda files in them. I have LazyData in my DESCRIPTION file set as true as well. I have tried both the data/ folder implementation and the R/sysdata.rda implementation using the function devtools::use_data() with the respective options of internal = FALSE and internal = TRUE.

However, when I try to build the package, or use devtools::install (which builds as well I assume), it fails and gives me the following error message:

Error in predict(finalModel, newInput) : object 'finalModel' not found

Where finalModel is stored within my .rda file.

Does anyone know any possible reasons why this might occur?

I also asked a coworker to install the package on his machine, but unfortunately he got the exact same error.

I made another test package as a 'sanity-check' by creating a simple linear model using the lm() function on datasets::swiss, and then made a test package with this newly created model as a .rda file. When I referenced this test model in a function within this test package, it eerily worked, despite the fact that (to the best of my knowledge) I used the exact same steps to create this new R package.

Also, I unfortunately cannot share the code for the package I am creating, but I am willing to share the code for the test package that uses the swiss dataset.

Thank you in advance.

EDIT: My .rda file I am putting in the package was created last year, if that has anything to do with it.

Cherry
  • 173
  • 1
  • 10
  • 1
    Did you set LadyData to true or did you set LazyData to true – Dason Dec 13 '17 at 23:02
  • And does using `data(finalModel)` allow you to access the data? – Dason Dec 13 '17 at 23:06
  • Sorry, I fixed my typo. Yes it was LazyData. Also, the data() function doesn't work. I get the same kind of error: "Warning in data(finalModel) : data set 'finalModel' not found". In addition, as far as I understand, I don't need to use such functions as the package should be able to determine where my finalModel is (in sysdata.rda)? Thank you for your response. – Cherry Dec 14 '17 at 14:08
  • Hi @Dason, as a last resort I decided to use my RStudio Server on my Ubuntu VM... and the package successfully installed! My host machine is on Windows 10, so maybe the problem has something to do with R for Windows or Hadley's devtools package? – Cherry Dec 14 '17 at 14:54
  • If you're using LazyData you shouldn't need to use data(finalModel) - I was just asking if you tried that because if using data allowed you to actually view finalModel then it would have pointed to an issue with the lazy loading. – Dason Dec 14 '17 at 16:35
  • Ah I see - thank you for explaining. – Cherry Dec 15 '17 at 19:33
  • I had a similar problem where I'd saved the file as sysdata.Rda instead of sysdata.rda. Case matters. See https://stackoverflow.com/a/62418855/4241780 – JWilliman Jun 16 '20 at 23:01

2 Answers2

1

I just solved a similar issue of having object 'objectName' not found that arose during package management. In my case, the issue related to losing the context of variables when working with parallelization.

When using parallel::clusterExport(cl, varlist=c("function-name")), clusterExport looks at .GlobalEnv for variable definitions. This wouldn't come up during debugging, as I always the variables defined in .GlobalEnv. The solution was to state the environment explicitly: parallel::clusterExport(cl, varlist=c("function-name"), envir=environment()). This ensures that the parallel processes have context of the variables within the data/ folder and R/sysdata.rda.

Source

Quinn Turner
  • 232
  • 1
  • 2
  • 11
0

If you have more than one internal file, you must save them together:

usethis::use_data(file_1,
         file_2,
         file_3,
         internal = TRUE,
         overwrite = TRUE)
Bruno Mioto
  • 382
  • 1
  • 10