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,280 points
111 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 9,050 points

Related Questions In Data Analytics

0 votes
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,000 points
205 views
0 votes
1 answer
0 votes
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,000 points
192 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://cran.us.r-p ...READ MORE

answered Nov 26, 2018 in Data Analytics by Maverick
• 10,000 points
154 views
0 votes
1 answer

R error: Unused arguments

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

answered Dec 13, 2018 in Data Analytics by Sophie may
• 9,050 points
437 views
0 votes
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
• 9,050 points
108 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.