【发布时间】:2019-03-19 19:24:44
【问题描述】:
我正在尝试将变量作为参数传递给 R 中的系统命令。
> system("ls>abc.csv") #this works
> k<-"abc.csv"
> system("ls>k") #this does not work
> system2("ls>k") #this does not work
sh: ls>k: command not found
> system("ls>$k") #this does not work
sh: $k: ambiguous redirect
【问题讨论】:
-
您需要按照您希望的方式实际构建字符串。查看 sprintf、paste 或任何其他字符串操作/连接函数。
-
可以将变量值粘贴到字符串
system(paste0("ls>", k))