【发布时间】:2021-12-04 08:56:35
【问题描述】:
我正在使用 optparse 调用一个参数,但我需要结果参数的字符串(变量 x)的格式为 "test", "test2", "test3"(引号用逗号分隔):
# Set up command line arguments
library("optparse")
option_list = list(
make_option(c("--test"), type="character", default=NULL,
help="test", metavar="character")
opt_parser = OptionParser(option_list=option_list);
opt = parse_args(opt_parser);
# grab argument into x variable
x <- (opt$pathcsv)
print(x)
进入命令行:
Rscript --vanilla riboeclip_ma.R --pathcsv="test test2 test3"
输出是字符类型:
"test test2 test3"
但是,我希望 x 变量的格式为 "test", "test2", "test3"
我的代码是这样设置的(注意我在向量中有"test", "test2", "test3"):
all_counts.poly.colData <-
data.frame(Condition =
c("test", "test2", "test3"))
但是,我想传递那个 x 变量来实现相同的结果(我正在尝试自动化这个过程)。
all_counts.poly.colData <-
data.frame(Condition =
c(x))
如果有更好的方法可以做到这一点,请告诉我,因为我还是 R 新手,昨天开始使用命令行参数。
【问题讨论】: