Run R script from command line

前端 未结 7 1802
甜味超标
甜味超标 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:39

    This does not answer the question directly. But someone may end up here because they want to run a oneliner of R from the terminal. For example, if you just want to install some missing packages and quit, this oneliner can be very convenient. I use it a lot when I suddenly find out that I miss some packages, and I want to install them to where I want.

    • To install to the default location:

      R -e 'install.packages(c("package1", "package2"))'
      
    • To install to a location that requires root privileges:

      R -e 'install.packages(c("package1", "package2"), lib="/usr/local/lib/R/site-library")' 
      

提交回复
热议问题