【问题标题】:How to pass command line parameters in R-Studio?如何在 R-Studio 中传递命令行参数?
【发布时间】:2013-08-29 04:28:41
【问题描述】:

我正在使用 LaTeX 和 R 生成地理报告。但我需要传递一个文本文件作为输入。我需要使用以下命令在终端上运行它:

R -e "Sweave('$PRGDIR/Test.Rnw')" <Input File> 1 0

在使用 IDE (R-Studio) 时,在终端上运行 Bu 不是一个好习惯。我如何使用 R-Studio 做到这一点?

【问题讨论】:

    标签: r parameter-passing rstudio


    【解决方案1】:

    我也遇到过类似的问题,我解决的方法是在shell调用中创建一个变量如下:

    R -e "file &lt;- 'input_file.txt'; param1 &lt;- 1; param2 &lt;- 2; Sweave('$PRGDIR/Test.Rnw')"

    .Rnw 脚本中使用exists 函数进行检查以搜索变量:

    if(exists("file")){
        # do stuff here
    } else{
        stop('I Need a file!')
    }
    

    【讨论】:

      猜你喜欢
      • 2011-04-11
      • 2016-05-13
      • 2011-08-22
      • 2016-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-27
      • 2016-03-25
      相关资源
      最近更新 更多