linux上安装R
1.yum安装R
yum install R
安装完成后,直接在终端输入R就可直接使用了,q()退出
查看Rscript路径
默认应该是 /usr/local/bin/Rscript
编写R代码文件
新建test1.R文件:touch test1.R
使文件可执行:chmod 777 test1.R
编写内容可参照如下示例,注意路径与上述一致!
#! /usr/local/bin/Rscript --vanilla
接收参数:Args <- commandArgs()
#! /usr/local/bin/Rscript --vanilla
Args = commandArgs(T)
print(Args[1])
for(i in 1:1000){
Sys.sleep(1)
print(i)
}
执行没报错,Rscript test1.R 123
编写shell文件
同路径下新建test1.sh文件:touch test1.sh
使文件可执行:chmod 777 test1.sh
编写内容可参照如下示例:
#!/bin/bash
v_day_two=`date -d"-2 day" '+%Y%m%d'`
echo "v_day_two:"${v_day_two}
echo "start: `date`"
/usr/local/bin/Rscript /root/test1.R ${v_day_two}
echo "end:`date`"
echo "SUCCESS"
执行效果如下:
上一篇:【mycat】Linux下mycat搭建配置全过程——初学者轻松上手篇