How to pass command-line arguments when calling source() on an R file within another R file

前端 未结 5 1222
盖世英雄少女心
盖世英雄少女心 2020-11-29 20:33

In one R file, I plan to source another R file that supports reading two command-line arguments. This sounds like a trivial task but I couldn\'t find a solution online. Any

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 21:08

    If you have one script that sources another script, you can define variables in the first one that can be used by the sourced script.

    > tmpfile <- tempfile()
    > cat("print(a)", file=tmpfile)
    > a <- 5
    > source(tmpfile)
    [1] 5
    

提交回复
热议问题