2

The problem:

I'm trying to install the devtools package for R. I'm using Ubuntu 18.04 LTS on WSL, the Windows Subsystem for Linux.

I'm able to install some packages just fine with a simple call to install.packages() from within R on WSL. However, other packages seem to give me trouble.

None of the following methods I've tried seem to work:
* I've tried installing the package with install.packages().
* I've tried installing from source into /usr/local/lib/R/site-library.
* I've tried installing from source into a personal library.

Error message:

I was recieving an error message like that discussed here, but I was unable to fix the problem by editing unpackPkgZip because it didn't exist.

The Question:

How can I install devtools on WSL?

twb10
  • 533
  • 5
  • 18
  • So you're saying that this doesn't work? https://www.digitalocean.com/community/tutorials/how-to-install-r-packages-using-devtools-on-ubuntu-16-04 If not, please provide the error message that the R terminal spits out. – ifconfig Jul 19 '19 at 06:11
  • Thanks! I should have included an error message. I bet that works, but I posted the solution that worked for me. – twb10 Jul 19 '19 at 11:34

1 Answers1

2

Solution:

I was able to fix the problem by starting over. I uninstalled Ubuntu and then reinstalled it. With a fresh install of Ubuntu 18.04 I followed these instructions. There are other online tutorials which probably work just fine, but I followed this one. You can ignore the bit about installing an rstudio server and the fsl package if you wish.

# Install R on WSL
sudo apt-get update -qq -y
sudo apt-get install -y wget git
OS_DISTRIBUTION=$(lsb_release -cs)
wget -O- http://neuro.debian.net/lists/${OS_DISTRIBUTION}.us-nh.full | sudo tee /etc/apt/sources.list.d/neurodebian.sources.list
sudo apt-key adv --recv-keys --keyserver hkp://pool.sks-keyservers.net:80 0xA5D32F012649A5A9
sudo apt-get update

sudo apt-get install libopenblas-base r-base
sudo apt-get update -qq -y
sudo apt-get install -y libgit2-dev 
sudo apt-get install -y libcurl4-openssl-dev libssl-dev
sudo apt-get install -y zlib1g-dev libssh2-1-dev libpq-dev libxml2-dev 
#sudo apt-get install -y libhdf5 # This didn't work.

Now try installing devtools in R.

# Install devtools
install.packages("devtools", repos = "https://cran.rstudio.com/")

Permission error:

If you encounter a permission error like the following...

Warning in install.packages("edgeR") :'lib = "/usr/local/lib/R/site-library"' is not writable Would you like to use a personal library instead? (y/n)

...you need to provide the user with write access to the directory where R packages are installed (see here). Try changing the group ownership of this directory:

# Who has ownership of /usr/local/lib/R/site-library/?
ls -l /usr/local/lib/R/
# drwxrwsr-x 1 root staff 512 Jul 18 21:38 site-library

# Change ownership.
sudo chgrp twesleyb /usr/local/lib/R/site-library/
ls -l /usr/local/lib/R/
#drwxrwxr-x 1 root twesleyb 512 Jul 18 21:38 site-library

# In this case I have write access, but in case you need to add it, try:
# $ sudo chmod g+w /usr/local/lib/R/site-library

You should now be able to install.packages("package").

I'm a linux novice, but I think this is an okay thing to do.

Update:

You can also try following duckmayr's instructions.

twb10
  • 533
  • 5
  • 18
  • 1
    No, don't start `R` via `sudo`. Make the default package directory, likely `/usr/local/lib/R/site-library`, writeable by you or your group, _i.e._ add yourself to group `staff`. That has been discussed before. – Dirk Eddelbuettel Jul 19 '19 at 11:38
  • Hey Dirk, If I don't launch R with sudo, and then try to install a package, I get an error like: Warning in install.packages("edgeR") :'lib = "/usr/local/lib/R/site-library"' is not writable Would you like to use a personal library instead? (y/n). So, as you suggest, I need to add myself the the group owning /usr/local/lib/R/site-library. But, when I do `sudo useradd -G staff twesleyb` I'm already on the group! Can you point me to where this has been discussed previously? – twb10 Jul 19 '19 at 18:02
  • Yes. I wrote "Make the default package directory [...] writeable by you or your group". Apparently you didn't. You likely need a combination of `chmod` and `chgrp` -- this is standard Unix fare of setting permissions and modes. But if you have never done it ... – Dirk Eddelbuettel Jul 19 '19 at 18:02
  • Sometimes you need to log in and out. Check with the `id` command what it says. And/or check the directory is group-writeable by the group you are a member of. Also, while I don;t use Windows or WSL, I read here recently that there were issues and that WSL2 was better. Good luck! – Dirk Eddelbuettel Jul 19 '19 at 18:02
  • Thanks Dirk. I think I've figured it out =) – twb10 Jul 19 '19 at 22:50
  • In that case write and tell and maybe post a self-answer if there was something other could learn from! – Dirk Eddelbuettel Jul 19 '19 at 22:51
  • @DirkEddelbuettel Maybe you could help me out on this related question: https://stackoverflow.com/questions/57137063/what-is-the-recommended-permissions-for-directories-containing-r-packages-on-lin? – twb10 Jul 21 '19 at 21:16