22

I'm using R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet" on Platform: x86_64-pc-linux-gnu (64-bit).

I have an issue installing new packages in R, using RStudio. When I call the install.packages() function, I get:

Warning in install.packages :
system call failed: Cannot allocate memory
Warning in install.packages :
installation of package ‘pastecs’ had non-zero exit status

The downloaded source packages are in
‘/tmp/Rtmpi0toFl/downloaded_packages’

I have installed R via shell commands and it worked ok. I've also decreased the swappiness value to 10, but I'm not sure if it has anything to do with the problem.

Thanks in advance!

gturri
  • 13,807
  • 9
  • 40
  • 57
  • What package are you trying to install? It does sound like a system problem rather than an R problem - how much RAM do you have free? – Oliver Keyes Nov 25 '14 at 20:43
  • I've tried installing "psych", "Hmisc" and "pastecs"; the same result for the three of them. I've tried: debug(install.packages) > install.packages("psych") > function (...) .rs.callAs(name, hook, original, ...) debugging in: install.packages("psych") MemTotal: 1909364 kB MemFree: 394692 kB Buffers: 3716 kB Cached: 354384 kB SwapCached: 0 kB Active: 1010724 kB Inactive: 320660 kB – Juan Carlos López Tavera Nov 25 '14 at 20:53
  • 3
    I got this error and resolved it by restarting my R session – David LeBauer May 13 '17 at 03:13
  • Monitor the RAM usage using "Gnome System Monitor". This desplay memory used/free ("free" actually means used for cache and buffers) and swap space used. I have 0 swap space used and about 3 GiB of RAM "free" and package installation fails with "Cannot allocate memory". Wut?? Could it be some other resource that is missing and the error message is wrong? RStudio has hoovered up 5 GiB so far. I just want to install `ggmosaic`! Restarting RStudio and relaunching install works, and RAM stays well within 2GiB used. There is a problem in RStudio somewhere. – David Tonhofer Oct 21 '19 at 23:43

3 Answers3

20

I figured out. I was all about the swap value.
There are several web pages that advice to decrease the default swap use in order to speed up Ubuntu. What I did to fix the problem.

In the terminal...

#Know the swap value    
cat /proc/sys/vm/swappiness
10
# Access the swap configuration
gksudo leafpad /etc/sysctl.conf

# Increase the swap usage to 30 (default is 60)
vm.swappiness=30

Then, I rebooted. And installed the packages happily without any problems.

  • 1
    Hi Juan, I have my swap at 60 and still not working, any idea? – JordanBelf Jan 27 '15 at 19:26
  • Hi Jordan, I still have that problem sometimes, I'm not an expert, but I think is because I don't have much RAM. It happened when I was installing the `gee` package, so I closed all the apps, and tried again... It worked for me. Good luck! – Juan Carlos López Tavera Feb 01 '15 at 20:48
  • 2
    Thanks a lot Juan, I managed to make it work by increasing the RAM in my instance too, so you are right, it looks like R doesn't get along very well with low RAM machines. – JordanBelf Feb 02 '15 at 00:57
  • OMG - this worked. I have no idea what I just did, but it worked. Gracias. – Super_John Jan 27 '16 at 04:58
  • 3
    If your swappiness is already 60, not enough memory is available to install the package. Restarting the server (sudo shutdown -r now) and installing the package first thing after it rebooted worked for me. – dter Jun 07 '16 at 18:32
  • I can confirm that @dter's suggestion worked for me. In short: rebooted and all good. Thank you. – timothyjgraham Dec 02 '16 at 00:15
  • Not sure if it was the change or the reboot, but it worked. Thanks! – cdutra Jun 17 '17 at 20:13
  • I have the exact problem. And my swap is already at 60, *and* I have 40 Gb of RAM in my box. When this happens, there is at least 16 Gb available. So, changing swap does not resolve the issue. – horaceT Sep 13 '17 at 19:22
  • I have experienced this in R 3.6, but not R 3.5. It seems that when you have more than app. half of your memory in use, running system commands from within R with system() will result in 'Cannot allocate memory' errors. Even simple ones like system("ls"). Most install.packages() commands will envoke system() commands and thus produce the error. The work around of re-starting R (or re-booting) will work simply because memory is flushed. Maybe someone can comment on what has been changed from R 3.5 to R 3.6. – Nightwriter Oct 08 '19 at 08:37
3

just restart the r-session. that did the trick for me.

joaoal
  • 1,892
  • 4
  • 19
  • 29
1

I confirm that the problem was with RAM space. i closed some background applications and it installed smoothly without any need to reboot my system

Danii-Sh
  • 447
  • 1
  • 4
  • 18