【发布时间】:2022-01-05 08:55:20
【问题描述】:
我正在开发一个 R 包,并希望在后台运行正在开发的包中的一些功能,使用 callr::r() 或 callr::r_bg()。
例如,我创建了一个包mytest,只有一个函数
hello <- function() {
print("Hello, world!")
}
然后使用pkgload::load_all() 加载包,该功能使用devtools 包加载开发中的包。之后,我可以在控制台中运行该函数,但不能在后台使用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
另一方面,如果我安装包并运行library(mytest),上面的代码运行没有问题
callr::r(function(){
mytest::hello()
})
#> [1] "Hello, world!"
请知道为什么callr::r() 找不到函数mytest::hello()?
看起来load_all() 没有将路径添加到可以找到包 mytest 的源代码的文件夹。
【问题讨论】: