我正在以批处理模式运行此R脚本。 4个文件路径通过shell脚本作为命名字符串(inPath1 ... inPath3,outPath)传入。这是shell脚本:
#!/bin/bash
R CMD BATCH --no-save --no-restore '--args inPath1="~/backtest/results/aapl-RESULTS.RData"
inPath2="~/backtest/results/adbe-RESULTS.RData"
inPath3="~/backtest/results/adi-RESULTS.RData"
outPath="~/backtest/profitBreakdown.csv' ~/Desktop/derp.R ~/Desktop/script.out
这是R脚本:
library(xts)
args <- commandArgs(trailingOnly=TRUE)
for(i in 1:3){
eval(parse(text=args[i]))
pathName <- paste("inPath", i, sep = "")
load(pathName)
}
我在输出中收到以下错误消息:
Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection
Calls: load -> readChar
In addition: Warning message:
In readChar(con, 5L, useBytes = TRUE) : cannot open compressed file 'inPath1', probable reason 'No such file or directory'
为什么会这样?文件和目录存在。我可以双击它们并用鼠标加载它们。每次使用load()后我是否必须关闭连接?