I am trying to install some packages in R using shell commands. I wrote a R file "installDependencies.R
" for installing packages. The file is as follows:
我正在尝试使用shell命令在R中安装一些包。我写了一个R文件“installDependencies”。R”安装包。文件如下:
packages <- c("xts","stringr","log4r")
# Function to check whether package is installed
is.installed <- function(mypkg){
is.element(mypkg, installed.packages()[,1])
}
for(package in packages){
# check if package is installed
if (!is.installed(package)){
install.packages(package)
}
}
Now I am trying to run this file using terminal. I created a shell script file inst.sh
and it is as follows:
现在我尝试使用终端运行这个文件。我创建了shell脚本文件inst.sh,如下所示:
#!/bin/bash
Rscript installDependencies.R
Whenever i run the file using ./inst.sh
command, the following error generated :
每当我使用。/inst运行文件时。sh命令,产生以下错误:
algotree@algotree-900X3C-900X4C-900X4D:~$ ./inst.sh
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Error in contrib.url(repos, type) :
trying to use CRAN without setting a mirror
Calls: install.packages -> grep -> contrib.url
Execution halted
algotree@algotree-900X3C-900X4C-900X4D:~$
1 个解决方案
#1
3
I had a similar issue before I set a CRAN mirror
在设置CRAN镜像之前,我也遇到过类似的问题
for(x in pkgs){
if(!is.element(x, installed.packages()[,1]))
{install.packages(x, repos="http://cran.fhcrc.org")
} else {print(paste(x, " library already installed"))}
}
#1
3
I had a similar issue before I set a CRAN mirror
在设置CRAN镜像之前,我也遇到过类似的问题
for(x in pkgs){
if(!is.element(x, installed.packages()[,1]))
{install.packages(x, repos="http://cran.fhcrc.org")
} else {print(paste(x, " library already installed"))}
}