I am trying to use the function insertSource (new in R 2.12) to update a function that I have made changes on.
However, when I use the function in this way:
insertSource('filename.R', package = 'mypackage')
I get the error:
Error in get(this, envir = envp) : object '.cacheOnAssign' not found
Unfortunately I can not come up with a simple reproducible example – if one would be helpful, please suggest how I can do it – but I have found that the following code does work:
system("echo 'nls <- function(nls) return(nls)' > foo.R")
insertSource('foo.R', package = stats)
One difference between the stats package and mypackage is the library location (mypackage is in ‘~/lib/R/’. (update): error still occurs when .libPaths('~/lib/R') is in .Rprofile, and googleing ‘.cacheOnAssign’ only returns 6 hits, two of them to this question.
Questions:
- what does the error mean?
- How can I use
insertSource?
Debugging
using options(error = recover)
options(error = recover)
Error in get(this, envir = envp) : object '.cacheOnAssign' not found
Called from: get(this, envir = envp)
Browse[1]> where
where 1: get(this, envir = envp)
where 2: insertSource("filename.R", "mypackage")
Browse[1]> ls()
[1] "q"
Browse[1]> n
>
not sure what to make of these results, and where to go from here
using options(error = browser) gives more information that I have placed in a text file
This is arguably a bug in
insertSource(). When you supply a file instead of an environment, it callsevalSource()on the file which synthesizes the.cacheOnAssignvariable (it will be simplyFALSE) in the source environment. That chokes the replacement since the variable does not necessarily exist in the package namespace.There are several ways around this, probably the easiest is to create the environment yourself and remove
.cacheOnAssignlike in this fix: