R system 或 system2 命令使用 paste 或 sprintf 来运行 bat 文件?

史蒂夫

我有一个 bat 文件,可以使用以下系统命令从 R 运行:

system('"C:\\PROGRA~1\\THERMO~1\\AFFYME~1\\APT-12~1.5\\bin\\apt-vars.bat" && cd "C:\\Users\\phyca\\Desktop\\R7\\R7_10-~1" && apt-cel-convert.exe --f text --i --cel-files CEL_FILE.txt')

但是当我尝试自动化我的整个过程时,我无法触发它。该行没有错误返回,但不会触发脚本。

#set apt location
apt_cnvrt <- "C:/Program Files/Thermo Fisher Scientific/Affymetrix Power Tools/APT-1.20.5/bin/apt-vars.bat"
#convert path format
apt_cnvrt <- gsub("/", "\\\\", apt_cnvrt)
#get short path
apt_cnvrt <- shortPathName(apt_cnvrt)
#store wd
outdir <- getwd()
#create file with list of files in dir
cel_list <- list.files(path = outdir, full.names = F, pattern = ".CEL")
fileConn<-file(paste0(outdir,"/CEL_FILE.txt"))
writeLines(c("cel_files", cel_list), fileConn)
close(fileConn)
#convert path format
outdir <- gsub("/", "\\\\", outdir)
#get short path
outdir <- shortPathName(outdir)
#set apt command
command <- "apt-cel-convert.exe --f text --i --cel-files CEL_FILE.txt"
#paste variables together to make: system('"C:\\Progra~1\\Thermo~1\\Affyme~1\\APT-1.20.5\\bin\\apt-vars.bat" && cd "C:\\Users\\me\\Desktop\\test" && apt-cel-convert.exe --format text --in-place --cel-files CEL_FILE.txt')
path <- noquote(paste0("'\"",apt_cnvrt,"\"", " && cd \"",outdir,"\" && ", command,"'"))
system(path)

当一切都说完并完成后,路径看起来像这样,它与完全有效的命令相匹配......但它不会触发脚本:

'"C:\\PROGRA~1\\THERMO~1\\AFFYME~1\\APT-12~1.5\\bin\\apt-vars.bat" && cd "C:\\Users\\me\\Desktop\\test" && apt-cel-convert.exe --f text --i --cel-files CEL_FILE.txt'

我已经尝试了各种版本的 paste、paste0、noquote、sprintf、system、system2、shell...等,但无法让它们中的任何一个接受变量来触发脚本。

史蒂夫

我能够让系统接受以下内容:

system(sprintf("\"%s\" && cd \"%s\" && %s", apt_cnvrt, outdir, command))

只要我在 R studio 中运行代码,代码就会运行到完成。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章