R: error while installing packages from terminal

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:

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:

#!/bin/bash

Rscript installDependencies.R

Whenever i run the file using ./inst.sh command, the following error generated :

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:~$ 

Answers


I had a similar issue before I set a CRAN mirror

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

Need Your Help

{% trans “string” %} not working on templates but {% trans variable %} does

django internationalization django-templates

I'm quite new to Django and I'm working on a project with i18n, the thing is that I have translated some variables using .manage.py makemessages / compilemessages on my template file, but when I ...

Using NSlog with cross platform style

ios nslog

I am creating an iphone test using c++,and I want to use nslog( the only way to show debug information?) whenever I want to include nslog function my cpp has to change to mm right? is it the only w...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.