1

我正在批处理模式下运行这个 R 脚本。4 个文件路径作为命名字符串 (inPath1...inPath3, outPath) 由 shell 脚本传入。这是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() 后是否必须关闭连接?

4

0 回答 0