3

I am running a ubuntu 12.04 instance, and have R3.0.2 loaded, but cannot get install.packages() to install packages. It downloads the files, but appears to not install them. Am I missing something here? I have never had this trouble before running ubuntu R instances. By the way, I have tried running the process as root instantiated with sudo R from command line but still no warning, no install. By the way, this problem is consistent across all packages I have tried to install.

Here is an example:

> install.packages("dataview")
Installing package into ‘/home/ubuntu/R/x86_64-pc-linux-gnu-library/3.0’
(as ‘lib’ is unspecified)
also installing the dependency ‘xtermStyle’

trying URL 'http://cran.rstudio.com/src/contrib/xtermStyle_2.2-4.tar.gz'
Content type 'application/x-gzip' length 15265 bytes (14 Kb)
opened URL
==================================================
downloaded 14 Kb

trying URL 'http://cran.rstudio.com/src/contrib/dataview_1.4-8.tar.gz'
Content type 'application/x-gzip' length 10696 bytes (10 Kb)
opened URL
==================================================
downloaded 10 Kb


The downloaded source packages are in
    ‘/tmp/Rtmp6FevA0/downloaded_packages’
> library(dataview)
Error in library(dataview) : there is no package called ‘dataview’ 

For what it is worth, I installed R with the following shell commands

#remove old versions
sudo apt-get remove r-base-core
#Adding deb to sources.list
sudo nano /etc/apt/sources.list    
deb http://cran.rstudio.com/bin/linux/ubuntu precise/

# Add key to sign CRAN packages
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
#Add specific PPA to the system
sudo add-apt-repository ppa:marutter/rdev
sudo apt-get update
sudo apt-get upgrade
#installing
sudo apt-get install r-base
sudo apt-get install r-base-dev

Thank you in advance for any help.

Jim Crozier
  • 1,198
  • 2
  • 14
  • 27
  • This may sound silly, but... have you rebooted _after updating the OS_? I had the exactly same "symptoms" on my remote Ubuntu machine. – KenM Feb 14 '14 at 17:30
  • Hey Ken, thanks for the idea. I tried rebooting but it is still having the same issue. – Jim Crozier Feb 14 '14 at 17:37
  • 1
    Is that really all the text you see when trying to install? After the last 'downloaded 10kb' the next thing it should do is `* installing *source* package ‘xtermStyle’` and then at least try and do the install. You got nothing? – Spacedman Feb 14 '14 at 17:52
  • That is all the text, but I am familiar with the correct output of install.packages(). Any how, I rebuilt the instance and everything is working now. There must have been a conflict that was not registering with the program. – Jim Crozier Feb 14 '14 at 20:38

7 Answers7

4

Finally (!!!) got this figured out. It is a conflict between mongodb and R's install.packages() command when Apache2 is installed (via lamp, I have not confirmed other installs). In order resolve just run

sudo service mongodb stop

on the shell, and then go into R and install the packages. You can restart the mongo server after you install the packages that you need. Hope that this helps someone. To reproduce the 'error' (I know, I know- not really an error) create a box on EC2 (although I imagine that the problem is not unique to EC2) using the following config:

#install mongodb:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/10gen.list
sudo apt-get update
sudo apt-get install mongodb-10gen

#install lamp server:
sudo tasksel #get lamp and openssh 

#install R
sudo nano /etc/apt/sources.list   
deb http://cran.rstudio.com/bin/linux/ubuntu precise/
gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9
gpg -a --export E084DAB9 | sudo apt-key add -
sudo apt-get update
sudo apt-get install r-base
sudo R

Inside R:

install.packages("dataview") #or whatever package

Packages will download, but not install as mentioned in the original post above.

To resolve, just stop the mongo server on the shell

sudo service mongodb stop

go back into R and install your packages and then go back the shell and re-start the server. Any illumination on what is causing the conflict (or in general debugging this sort of issue short of re-trying the command step by step throughout the process) would be appreciated. Notice that the install.packages() command works fine if only the mongodb server is running without Apache installed, but stopping the Apache server does not resolve the conflict.

For reference, this is a Ubuntu 12.04 64-bit instance, with R 3.0.2, Mongodb-10gen, and Apache2.

Jim Crozier
  • 1,198
  • 2
  • 14
  • 27
3

When I installed R Server on Ubuntu 12.04, I forgot to set up swaps: https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-12-04

When I set up swaps according to the tutorial above, it allowed me to install R packages. This may be the issue you are having.

allthesignals
  • 197
  • 1
  • 12
1

I might have few suggestions from my past experience, hope that helps:

I would run R as a super user sudo su. Then would try to install package. Also would make sure that package is being installed in default location from where R try load packages that is I believe /usr/local/lib/R/site-library.

Give this a try and see if it works. If not then I would also try another workaround to fool R by copying my installed package in /home/ubuntu/R/x86_64-pc-linux-gnu-library/3.0 to /usr/local/lib/R/site-library as root and see if that helps.

Good luck

Dev Patel
  • 272
  • 1
  • 5
  • 11
1

This is a note to my answer below but is too long to fit in a note. This problem is a little more complicated than I thought. It appears that if lamp is loaded you need to stop mysql in order to run any system command in R (therefore install.packages() is not unpacking, although it is unclear why the download is working- file under joys of open source). A related problem here. That is, you can replicate the issue by just installing R + lamp (I am also running RStudio Server which may play into it, but I do not thing that it does). If the mysql service is running the following error pops up on R start up

Error in system(paste(which, shQuote(names[i])), intern = TRUE, ignore.stderr = TRUE) : 
cannot popen '/usr/bin/which 'pdflatex' 2>/dev/null', probable reason 'Cannot allocate memory'

(by the way, this is not an out of memory issue as there is plenty of memory on the server). My suggestion if you need to run a lamp server (and/or other services on apache2) is to install from the command line (not tasksel, see below) like such (make sure to take the security precautions of course(!))

sudo apt-get install apache2
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

and then

sudo service mysql stop

if you need to run system commands in R. I actually was not able to get the R sessions to ever install.packages() again once a tasksel lamp package was installed and a user was added, no matter which services I stopped. Similarly, if you have mongo or another server running, they will need to be stopped as well.

Hope that this saves someone some grief. Again, if anyone can illuminate what the underlying issue here is I would really appreciate it- I would really like to be able to run the mysql service while executing complex R commands.

Again, working with R 3.0.2, apache2, and ubuntu 12.04. I also replicated the issue in ubuntu 13.10 just to see if that would help (it didn't).

Community
  • 1
  • 1
Jim Crozier
  • 1,198
  • 2
  • 14
  • 27
1

Ok, so I was running into the same problem... Make sure you allocate enough memory to your VM. The default VM memory for Vagrant is 512m... Increase it to 2048m and all should work fine...

I use this in my vagrant file to increase the memory:

  config.vm.provider "virtualbox" do |vb|
    # Use VBoxManage to customize the VM. For example to change memory:
    vb.customize ["modifyvm", :id, "--memory", "2048"]
  end
Ben B
  • 721
  • 6
  • 4
0

I had this problem on CentOS, what finally worked for me was this:

Create some directory, lets say /data/Rpackages, then have R download the tar.gz files to it by running

install.packages("RMySQL", destdir="/data/Rpackages/")

Then install the packages offline manually (note that if the previous command downloaded other dependent packages you'll have to install those in order as well):

install.packages(repos=NULL, pkgs="/data/Rpackages/DBI_0.2-7.tar.gz")
install.packages(repos=NULL, pkgs="/data/Rpackages/RMySQL_0.9-3.tar.gz")
Morad
  • 704
  • 4
  • 13
  • That didn't work either; I got this message on install: `Installing package into ‘/home/vagrant/R/i686-pc-linux-gnu-library/3.0’` followed by this message when I tried to load the library: `Error in library("DBI") : ‘DBI’ is not a valid installed package`. I tried specifying the library location with this `library("DBI",lib.loc="/home/vagrant/R/i686-pc-linux-gnu-library/3.0")` but just got this error `Error in library("DBI", lib.loc = "/home/vagrant/R/i686-pc-linux-gnu-library/3.0") : ‘DBI’ is not a valid installed package` – samhiggins2001 Jul 24 '14 at 17:19
0

Had the same problem on Ubuntu Server 14.04 LTS in AWS ... t1.micro instance with 600MB free memory .... so have added additional swap space as rcomended above and it staretd working fine.

The solution to add swap space on EC2 instance is described i.e. here: How do you add swap to an EC2 instance?