Error with insertSource (): "object" .cacheOnAssign "not found"

I am trying to use a function insertSource(new in R 2.12) to update a function that has been modified.

However, when I use the function in this way:

insertSource('filename.R', package = 'mypackage')

I get an error message:

Error in get(this, envir = envp) : object '.cacheOnAssign' not found

Unfortunately, I cannot come up with a simple reproducible example - if it were useful, suggest how I can do this, but I found that the following code really works:

system("echo 'nls <- function(nls) return(nls)' > foo.R")
insertSource('foo.R', package = stats)

One of the differences between the statistics package and mypackage is the location of the library (mypackage is in '~ / lib / R /. (Update): the error still occurs when it .libPaths('~/lib/R')is in .Rprofileand googleing'.cacheOnAssign' only returns 6 hits, two of them to this question.

Questions:

  • What does the error mean?
  • insertSource?

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
>

, ,

options(error = browser), ,

+3
2

, , insertSource(). , evalSource() , .cacheOnAssign ( FALSE) . , .

, , .cacheOnAssign, :

insertSource <- function(source, package="", ...) {
    if (!is(source, "environment")) {
        source <- evalSource(source, package = package, lock = FALSE)
        rm(.cacheOnAssign, envir = source)
    }
    methods::insertSource(source, package = package, ...)
}
+5

, bugger, , .:)

, , , , , , . , , insertSource, .

, functions insertSource(). , :

# Specify the new source file and the package to be updated
tmpFname <- "mySource.R"
myPkgName <- "myPkg"

# Load the package - it might not already be loaded
do.call(library, list(myPkgName))

# We need to know which functions are going to be produced, so we run `evalSource()`
tmpEval <- evalSource(tmpFname, package = myPkgName)

# Not everything from `evalSource()` is a function, so omit that stuff
newFuncs <- ls(tmpEval)[-match(c("packageName", "sourceFile"), ls(tmpEval))]

# Now, we can submit a proper incantation to `insertSource()`
insertSource(tmpFname, package = myPkgName, functions = newFuncs)

:

Modified functions inserted through trace():  (... my functions here ...)

, . insertSource() evalSource() .


1. , insertSource(), . ( , , ), . , / evalSource insertSource.

+1

All Articles