R代码可以像这样在后台进程中运行
callr::r(function(){ 2 * 2 })
# [1] 4
当我尝试这样做时,args
我不知道如何访问它们。我尝试了一些明显的事情:
callr::r(function(){ 2 * 2 }, args = list(x=3))
callr::r(function(){ 2 * x }, args = list(x=3))
callr::r(function(){ 2 * args$x }, args = list(x=3))
callr::r(function(){
args <- commandArgs()
2 * args$x
},
args = list(x=3))
# Error: callr subprocess failed: unused argument (x = base::quote(3))
# Type .Last.error.trace to see where the error occurred
我也尝试使用调试,browser()
但在这种情况下它没有以通常的方式工作。
问题
如何将参数传递给调用的后台进程callr::r()
并在后台进程中访问这些参数?