使用shell脚本测试R库加载功能

时间:2017-05-12 11:00:57

标签: r bash shell

我在我的Linux系统中安装了R。我还安装了一个包“x”。我想编写一个简单的shell脚本来检查该库是否正确加载。还可以说,在'x'包中有一个名为'f'的API,我的shell脚本应该能够运行它并验证它是否正常工作而没有任何错误。

简而言之,我想借助shell脚本测试下面的R功能。如果下面的东西工作返回true其他错误

$ R 


Copyright (C)  The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

R > library(x)
 library loaded
R> f(c(1,2,3))
 #No error thrown

1 个答案:

答案 0 :(得分:1)

应该像这样工作:

R --no-save <<EOF
library(x)
f(c(1,2,3))
EOF
if test $? = 0 ; then
  echo "good"
else
  echo "bad"
fi