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

前端 未结 5 1224
盖世英雄少女心
盖世英雄少女心 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条回答
  •  囚心锁ツ
    2020-11-29 20:56

    The simplest solution is to replace source() with system() and paste. Try

    arg1 <- 1
    arg2 <- 2
    system(paste("Rscript file_to_source.R", arg1, arg2))
    

提交回复
热议问题