【问题标题】:Running R function as command line script with arguments将 R 函数作为带有参数的命令行脚本运行
【发布时间】:2012-06-25 05:32:08
【问题描述】:

假设我有以下脚本

k <- as.numeric(readline("Start Index: "))
tot <- NULL

for (i in 1:k){
    tot <- c(tot, i)
}
write.csv(tot, "test.csv")

我想从命令行运行这个脚本。我怎样才能运行它以便它仍然要求用户输入 (k)。或者我可以在 CMD 命令中添加 k 的值作为参数吗?我在 Linux 上。

【问题讨论】:

标签: r command-line


【解决方案1】:

?commandArgs 中的信息可能对您有所帮助。

来自描述:

 Provides access to a copy of the command line arguments supplied
 when this R session was invoked.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-02
    • 2017-11-30
    • 2016-12-18
    • 1970-01-01
    • 2018-12-22
    • 2012-10-26
    • 1970-01-01
    • 2015-05-18
    相关资源
    最近更新 更多