Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在R中的字符串引号内指定变量?_R_String_Variables_Escaping_Rscript - Fatal编程技术网

如何在R中的字符串引号内指定变量?

如何在R中的字符串引号内指定变量?,r,string,variables,escaping,rscript,R,String,Variables,Escaping,Rscript,嗨,Stack Overflow社区,非常感谢您在这个问题上提供的帮助 我对编写一个非交互式Rscript感兴趣,它指定从命令行读入的变量。例如: Rscript ./script {1} {2} {1}是我传递给脚本的参数,{2}是对应于完整路径的参数,该路径指向一个由一列组成的文本文件,其中包含数字和名称 我编写了一个小Rscript,其功能是读取文本文件并删除包含特定字符串的行。我希望字符串对应于我在脚本开头指定并在命令行上提供的变量。到目前为止,我的脚本是: args = comman

嗨,Stack Overflow社区,非常感谢您在这个问题上提供的帮助

我对编写一个非交互式Rscript感兴趣,它指定从命令行读入的变量。例如:

Rscript ./script {1} {2}
{1}是我传递给脚本的参数,{2}是对应于完整路径的参数,该路径指向一个由一列组成的文本文件,其中包含数字和名称

我编写了一个小Rscript,其功能是读取文本文件并删除包含特定字符串的行。我希望字符串对应于我在脚本开头指定并在命令行上提供的变量。到目前为止,我的脚本是:

args = commandArgs(trailingOnly=TRUE)

POP = args[1]
FREQ = args[2]

# read the file in 
POP.freq <- paste0("FREQ")

# write a function to remove the rows that hold the string "POP"

clean_names <- function(x, ...) { 
  POP.freq[!POP.freq$POP == "POP",]
}
args=commandArgs(trailingOnly=TRUE)
POP=args[1]
FREQ=args[2]
#在中读取文件

POP.freq而不是
“POP”
你能坚持使用
args[1]
吗,即
POP.freq[!POP.freq$POP==args[1],]
?或者你应该使用
POP
而不加引号,因为它是一个变量。不幸的是,这两个选项都不能达到预期的结果。R不将两者识别为指定变量。我想知道这是不是因为它的语法加上流行音乐?(第一种情况下为a$,第二种情况下为a“”)