Running R Code from Command Line (Windows)

前端 未结 4 935
南笙
南笙 2020-12-02 17:41

I have some R code inside a file called analyse.r. I would like to be able to, from the command line (CMD), run the code in that file without having to pass through the R te

4条回答
  •  感动是毒
    2020-12-02 18:02

    save the following in a text file

    f1 <- function(x,y){
    print (x)
    print (y)
    }
    args = commandArgs(trailingOnly=TRUE)
    f1(args[1], args[2])
    

    No run the following command in windows cmd

    Rscript.exe path_to_file "hello" "world"
    

    This will print the following

    [1] "hello"
    [1] "world"
    

提交回复
热议问题