在PM2群集模式下运行R脚本

在PM2群集模式下运行R脚本,r,pm2,R,Pm2,我有一个R脚本,在PM2的Fork模式下运行良好。我使用以下命令运行它: pm2 -f start --interpreter="Rscript" <path> pm2-f start--interpreter=“Rscript” 当我试着在PM2的集群模式下运行时,就像这样 pm2 -f start --interpreter="Rscript" <path> -i 2 pm2-fstart--解释器=“Rscript”-i2 它失败,出现以下错误 Refere

我有一个R脚本,在PM2的Fork模式下运行良好。我使用以下命令运行它:

pm2 -f start --interpreter="Rscript" <path>
pm2-f start--interpreter=“Rscript” 当我试着在PM2的集群模式下运行时,就像这样

pm2 -f start --interpreter="Rscript" <path> -i 2
pm2-fstart--解释器=“Rscript”-i2
它失败,出现以下错误

ReferenceError: setwd is not defined
    at Object.<anonymous> (<<Path>>.R:1:63)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at /usr/lib/node_modules/pm2/lib/ProcessContainer.js:307:23
    at /usr/lib/node_modules/pm2/node_modules/async/lib/async.js:52:16
    at /usr/lib/node_modules/pm2/node_modules/async/lib/async.js:1209:30
    at WriteStream.<anonymous> (/usr/lib/node_modules/pm2/lib/Utility.js:147:13)
ReferenceError:未定义setwd
反对。(.R:1:63)
在模块处编译(Module.js:570:32)
在Object.Module.\u extensions..js(Module.js:579:10)
在Module.load(Module.js:487:32)
在tryModuleLoad时(module.js:446:12)
在Function.Module.\u加载(Module.js:438:3)
在/usr/lib/node_modules/pm2/lib/ProcessContainer.js:307:23
at/usr/lib/node_modules/pm2/node_modules/async/lib/async.js:52:16
at/usr/lib/node_modules/pm2/node_modules/async/lib/async.js:1209:30
在WriteStream。(/usr/lib/node_modules/pm2/lib/Utility.js:147:13)
我是否应该对R脚本进行任何更改以使其能够在集群模式下运行

我的R脚本的内容是

setwd(<folderpath>)
source("../supportingFile.R")
startWebListener("file.R", 8080)
setwd()
源(“../supportingFile.R”)
startWebListener(“file.R”,8080)
如果删除setwd命令,则在源命令上引发相同的错误


谢谢

似乎PM2试图将实例数传递给R脚本。一般来说,在脚本中使用
setwd
不是一个好主意。因此,我的文件的内容是setwd()/n source(../funs5.R”)/n startWebListener(“name.R”,8080)如何将其更改为不使用setwd?为什么在脚本中使用setwd不是一个好主意呢?另外,如果我删除setwd命令,下一行(源命令)会抛出相同的错误。