1. Rscript a.R
2. R CMD BATCH a.R
3. 编写脚本是第一行加入Rscript的路径,如
#!/usr/bin/env Rscript
sayHello <- function(){
print('hello')
}
然后在终端运行该脚本
sayHello()
4. 运行一行命令
R -e 'install.packages(c("package1", "package2"))' # install to default location.
sudo R -e 'install.packages(c("package1", "package2"), lib="/usr/local/lib/R/site-library")' # install to location that requires root.
安装包到全局
sudo su - -c "R -e \'install.packages(c("package1", "package2"))\' "
此处的 -e 参数是 expr 的意思