1) 写一个R的脚本
写成R脚本,之后放入系统运行。比如R脚本test.r:
#! /usr/lib/R/bin/Rscript --vanilla
# options:默认--restore -- save --no-readline;--help 查看帮助信息;--version 查看R版本;--slave只打印R脚本的输出,而不显示脚本具体执行情况;--no-timing 去除输出文档结束的运行时间输出。
args <- commandArgs(TRUE)
paste(c("I", "like", args[1], "and", args[2], "!"), collapse = " ")
print(args)
2)赋予权限,通过Rscript执行,
[duqi.yc@hdpdev1 R]$ chmod +x test.r
[duqi.yc@hdpdev1 R]$ ~/R/R-3.0.2/bin/Rscript ~/scripts/R/test.r tea coff eoo fff
[1] "I like tea and coff !"
[1] "tea" "coff" "eoo" "fff"
3) Rscrip中load数据
You can create an environment and load the data into the environment.
tmpenv <- new.env()
load("R.RData", envir=tmpenv)
x <- tmpenv$Data