9

I need devtools because I need the function install_github to install the non-CRAN package digitize here. I installed R by

sudo apt-get install r-cran-robustbase

I did not install R's packages right away, as terdon's answer proposes, but I could correct the permissions:

sudo chmod 755 /usr/lib/R/site-library/

which I think is the default setting. I then had to do as rcs' answer proposes, to successfully install devtools and tpoisot/digitize but only with

sudo apt-get install libssl-dev
sudo apt-get install libcurl4-openssl-dev
R
install.packages('httr')
install.packages('git2r')
install.packages('devtools')
library(devtools)
install.packages('readbitmap')
install_github('tpoisot/digitize')

The output of the last command can be

Skipping install for github remote, the SHA1 (d16e28b9) has not changed since last install.
  Use `force = TRUE` to force installation

Do install_github('tpoisot/digitize', force = TRUE) but you may get

...
'/usr/lib/R/bin/R' --no-site-file --no-environ --no-save --no-restore --quiet  \
  CMD INSTALL '/tmp/RtmpX8eOLX/devtools57475d25a113/tpoisot-digitize-d16e28b'  \
  --library='/usr/local/lib/R/site-library' --install-tests 

Error: ERROR: no permission to install to directory ‘/usr/local/lib/R/site-library’
Error: Command failed (1)

I could not find a way to install digitize without sudo. So do sudo R, and repeat the same and you get

...
'/usr/lib/R/bin/R' --no-site-file --no-environ --no-save --no-restore --quiet  \
  CMD INSTALL '/tmp/RtmpAlAT4e/devtools57e864e8c490/tpoisot-digitize-d16e28b'  \
  --library='/usr/local/lib/R/site-library' --install-tests 

* installing *source* package ‘digitize’ ...
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (digitize)

Add masi to the existing group staff to work without sudo in R; which you need also in a fresh installation

sudo usermod -a -G staff masi

Tests of the installation

  1. I follow the guide here. I start R in $HOME/Pictures/ without sudo and use their test image here.

  2. Select four points in the axes with mouse cal = digitize::ReadAndCal('Rintro-snail1.jpg')

enter image description here

  1. Do data.points = digitize::DigitData(col = 'red') and choose manually points which are your data points

enter image description here

  1. I close the Plot window by doing second-click.

  2. Do df = digitize::Calibrate(data.points, cal, 0.1, 0.4, 0.0, 0.6) and seeing df

           x  y
    1  71.50 NA
    2  65.65 NA
    ...
    24 26.80 NA
    

    Doing head(df)

          x  y
    1 71.50 NA
    2 65.65 NA
    3 64.60 NA
    4 60.85 NA
    5 59.05 NA
    6 58.15 NA
    

Installation Details

  • In R and without sudo

    > .Library
    [1] "/usr/lib/R/library"
    > > .libPaths()
    [1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library"      
    [3] "/usr/lib/R/library"  
    
  • Command ls /usr/lib/R/library/ which does not list devtools. Why?

    base       compiler   grid        methods   rpart    survival
    boot       datasets   KernSmooth  mgcv      spatial  tcltk
    class      foreign    lattice     nlme      splines  tools
    cluster    graphics   MASS        nnet      stats    translations
    codetools  grDevices  Matrix      parallel  stats4   utils
    
  • Command ls -la /usr/local/lib/R/

    total 12
    drwxrwsr-x 3 root staff 4096 touko 19 22:25 .
    drwxr-xr-x 5 root root  4096 touko 19 22:25 ..
    drwxrwsr-x 2 root staff 4096 touko 19 22:25 site-library
    
  • Command ls -la /usr/local/lib/

    total 20
    drwxr-xr-x  5 root root  4096 touko 19 22:25 .
    drwxr-xr-x 14 root root  4096 touko 19 22:13 ..
    drwxrwsr-x  4 root staff 4096 huhti 21 01:13 python2.7
    drwxrwsr-x  3 root staff 4096 huhti 21 01:08 python3.5
    drwxrwsr-x  3 root staff 4096 touko 19 22:25 R
    
  • Command R_LIBS_USER="/usr/local/lib/R/site-library/" R

     R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree"
     Copyright (C) 2015 The R Foundation for Statistical Computing
     Platform: x86_64-pc-linux-gnu (64-bit)
     ...
    
  • library(devtools) gets loaded

Differential tools

Reasons for previous bugs

  • No clean system: systems which were upgraded from 14.04, 15.10, etc.
  • Messed up permissions/owners because of the previous thing.
  • Own mistakes in the process.
  • No backups in the case of failure.
  • ...
  • missing docs

System: Ubuntu 16.04 64 bit in a clean installation
Hardware: Dell PC 2013, Macbook Air 2013-mid, ...

Léo Léopold Hertz 준영
  • 6,788
  • 29
  • 91
  • 193
  • I can't reproduce this on my Arch system. Installing `devtools` through `sudo R`, let me run `library(devtools)` from a non-sudo R session. Please add the output of i) `.Library` run from a normal `R` session and ii) from `sudo R` and iii) check for a `devtools` subdirectory in the path provided by those commands. On my system, it's at `/usr/lib64/R/library/devtools/`. – terdon May 07 '16 at 12:20
  • OK, is there a `devtools` subdirectory in `/usr/lib/R/library`? – terdon May 07 '16 at 12:26
  • My guess is that the installation wasn't actually successful then. Try it again, and pay close attention to the output. Were you *really* able to run `library(devtools)` and successfully load the library? – terdon May 07 '16 at 12:30
  • OK, I think I know what the problem is. One more thing, what do you get if you run `.libPaths()` from R? – terdon May 07 '16 at 12:54
  • See updated answer. – terdon May 07 '16 at 13:02
  • 1
    Argh, OK, and do you have a devtools subdir in `/usr/local/lib/R/site-library`? You probably do. If so, see my (newly) updated answer. – terdon May 07 '16 at 13:12
  • That's OK, that's because you don't have permissions to read that. Try `sudo ls /usr/local/lib/R/site-library`. Even better, ping me in [/dev/chat](http://chat.stackexchange.com/rooms/26/dev-chat) and we can sort this out. You seem to have screwed up the permissions in `/usr/local/lib/R`. – terdon May 07 '16 at 13:23
  • That's a completely different issue and not really on topic here. You have successfully installed everything, now you need help running an R script. I recommend you ask on [so] instead. – terdon Jun 13 '16 at 11:54
  • The only issue I see here is that closing the graph window unsets the variable. Is there anything else left? – terdon Jun 13 '16 at 11:58
  • This question combines a linux installation issue with the issue of using the digitize package. The latter problem isn't linux/unix issue but is answered here https://github.com/tpoisot/digitize/issues/11 – jaimedash Jun 16 '16 at 22:12

2 Answers2

11

httr imports the openssl package which needs as system requirement libssl-dev (sudo apt install libssl-dev)

------------------------- ANTICONF ERROR ---------------------------
Configuration failed because openssl was not found. Try installing:
 * deb: libssl-dev (Debian, Ubuntu, etc)
...

The curl package needs as system requirement libcurl4-openssl-dev:

------------------------- ANTICONF ERROR ---------------------------
Configuration failed because libcurl was not found. Try installing:
 * deb: libcurl4-openssl-dev (Debian, Ubuntu, etc)
...

So, to install you will need to run:

sudo apt-get install libssl-dev
sudo apt-get install libcurl4-openssl-dev

Then start an R shell with sudo R and:

install.packages('httr')
install.packages('git2r')
install.packages('devtools')
library(devtools)
install_github('tpoisot/digitize')
Léo Léopold Hertz 준영
  • 6,788
  • 29
  • 91
  • 193
rcs
  • 649
  • 1
  • 6
  • 11
2

As a general rule, you don't just change the permissions of system directories! That's what root access is for. Put the permissions back the way you found them and next time run sudo R and install.packages from the resulting, root R shell.

Now, the reason you can't install is right there in the output you show:

ERROR: dependencies ‘httr’, ‘git2r’ are not available for package ‘devtools’

Apparently, as explained by rcs, on Ubuntu, you need to install libssl-dev and libcurl4-openssl-dev first.


The next issue is that your root user's R installation has /usr/local/lib/R/site-library as the first directory in the output of .libPaths and that is not in the paths of your regular user. Since it is the first entry for root, that's where your library was installed:

 Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)

So, a simple solution is to create a file called ~/.Rprofile and add this line to it:

.libPaths("/usr/local/lib/R/site-library/")

Alternatively, or additionally, you could include a line like

   .libPaths("/home/masi/Rlibs")

That would let you install libraries into the directory /home/masi/Rlibs (chose whatever name you want) in future and so avoid the need for sudo R.


Alternatively, you could set the environmental variable R_LIBS_USER to /usr/local/lib/R/site-library/ (or /home/masi/Rlibs or wherever else your libraries are being installed). Just add this line to your ~/.profile:

R_LIBS_USER=/usr/local/lib/R/site-library/
terdon
  • 234,489
  • 66
  • 447
  • 667
  • @Masi did you try my suggestions above? You can test that this is the problem by running `R_LIBS_USER="/usr/local/lib/R/site-library/" R` and then, in R, run `library(devtools)`. – terdon May 07 '16 at 13:15
  • If you execute `.libPaths("/home/masi/Rlibs")` after `.libPaths("/usr/local/lib/R/site-library/")` that will replace the original setting. If you want to add a library directory it should be `.libPaths(c(.libPaths(), "/home/masi/Rlibs") )` – 42- May 07 '16 at 17:05