Run R script from command line

前端 未结 7 1793
甜味超标
甜味超标 2020-11-22 09:20

I have a file, called a.r, it has a chmod of 755,

sayHello <- function(){
   print(\'hello\')
}

sayHello()

Ho

7条回答
  •  庸人自扰
    2020-11-22 09:38

    You need the ?Rscript command to run an R script from the terminal.

    Check out http://stat.ethz.ch/R-manual/R-devel/library/utils/html/Rscript.html

    Example

    ## example #! script for a Unix-alike
    
    #! /path/to/Rscript --vanilla --default-packages=utils
    args <- commandArgs(TRUE)
    res <- try(install.packages(args))
    if(inherits(res, "try-error")) q(status=1) else q()
    

提交回复
热议问题