R error when installing packages from terminal

0 votes

I am using shell commands to install some packages in R.  I have a R file "installDependencies.R" for installing packages, this is the content of the file:

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)
  }
}

Next I'm running this on the terminal. This is the shell script I created:

#!/bin/bash

Rscript installDependencies.R

I get the following error while running the file:

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:~$ 
Dec 14, 2018 in Data Analytics by Tyrion anex
• 8,700 points
2,816 views

1 answer to this question.

0 votes

I faced the same problem, you must set a CRAN mirror like so:

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"))}
}
answered Dec 14, 2018 by Sophie may
• 10,620 points

Related Questions In Data Analytics

+1 vote
1 answer

"Error in eval(ei, envir) : object 'RDX2' not found" when trying to source the code in R

This is a very common issue that ...READ MORE

answered Oct 30, 2018 in Data Analytics by Maverick
• 10,840 points
5,109 views
0 votes
1 answer
+1 vote
1 answer

Error saying "vector size cannot be NA" when using R with data mining

You can use the removesparseterm function.  Removes sparse ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,840 points
4,832 views
0 votes
1 answer
0 votes
1 answer

Error saying " cannot open the connection" when trying to install a package in R

Try install.packages(“package_name”, repos="http://cr ...READ MORE

answered Nov 26, 2018 in Data Analytics by Maverick
• 10,840 points
9,154 views
+1 vote
1 answer

R error: Unused arguments

 invoke REBMIX by trying this: REBMIX[[i, j, k]] ...READ MORE

answered Dec 14, 2018 in Data Analytics by Sophie may
• 10,620 points
6,488 views
+1 vote
1 answer

R & MySQl : Error connecting to Database

Check the dbConnect's documentation, you must pass values ...READ MORE

answered Dec 14, 2018 in Data Analytics by Sophie may
• 10,620 points
2,089 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP