I'm devoloping an R package and want to run some of the functions in the package under development in the background, using callr::r()
or callr::r_bg()
.
As an example, I created a package mytest with only one function
hello <- function() {
print("Hello, world!")
}
Then loaded the package with pkgload::load_all()
, the function to load a package in development using devtools package. After this, I can run the function in the console but not in the background using callr::r()
.
callr::r(function(){
mytest::hello()
})
#> Error: callr subprocess failed: there is no package called 'mytest'
#> Type .Last.error.trace to see where the error occurred
On the other hand, if I install the package and run library(mytest)
, the code above run without problems
callr::r(function(){
mytest::hello()
})
#> [1] "Hello, world!"
Please, any clue why callr::r()
does not find function mytest::hello()
?
It looks like load_all()
is not adding the path to the folder where the source code of the package mytest can be found.