问题
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.
回答1:
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.
回答2:
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.
回答3:
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
回答4:
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).
回答5:
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
回答6:
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")
回答7:
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?
来源:https://stackoverflow.com/questions/21785616/ubuntu-12-04-r-install-packages-does-not-work-no-warning-no-install