Ubuntu – How tonstall R’s devtools and digitize

rsoftware installationUbuntu

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, …

Best Answer

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')
Related Question