问题
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.
回答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
来源:https://stackoverflow.com/questions/47803225/r-package-build-install-error-object-not-found-even-though-i-have-it-in-r-sys