Ubuntu – How to rectify the numerous error messages that appear when installing packages

r

I am using Ubuntu 18.04 with R (3.4.4)/RStudio (1.2.1335) and am having great difficulty in installing some packages. For the purpose of this question, I will use the Tidyverse as an example.

Using RStudio, I run:

install.packages("tidyverse", dependencies = TRUE)

And after what looks like a good start ("trying X-package, downloading X-package…"), the installation then becomes plagued with error messages galore. (Note this happens regardless of whether I set dependencies to TRUE or FALSE.)

I have read the error messages' advice and followed the instructions and nothing changes. I have spent literally hours researching ways online to figure this out and trying different methods (such as specifying folders/directories to store the packages to, reinstalling some software, removing other software, and several other things) and still nothing changes.

I have fully uninstalled and reinstalled R/RStudio and still the same thing occurs.

For example, when I run the above code, this is where things start to go wrong:

* installing *source* package ‘curl’ ...
** package ‘curl’ successfully unpacked and MD5 sums checked
Found pkg-config cflags and libs!
/home/mus/.R/Makevars:1: *** missing separator. Stop.
/home/mus/.R/Makevars:1: *** missing separator. Stop.
/home/mus/.R/Makevars:1: *** missing separator. Stop.
Using PKG_CFLAGS=-I/usr/include/x86_64-linux-gnu
Using PKG_LIBS=-lcurl
------------------------- ANTICONF ERROR ---------------------------
Configuration failed because libcurl was not found. Try installing:
 * deb: libcurl4-openssl-dev (Debian, Ubuntu, etc)
 * rpm: libcurl-devel (Fedora, CentOS, RHEL)
 * csw: libcurl_dev (Solaris)
If libcurl is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libcurl.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
--------------------------------------------------------------------
ERROR: configuration failed for package ‘curl’
* removing ‘/home/mus/R/x86_64-pc-linux-gnu-library/3.4/curl’
Warning in install.packages :
  installation of package ‘curl’ had non-zero exit status
* installing *source* package ‘haven’ ...
** package ‘haven’ successfully unpacked and MD5 sums checked
** libs
/home/mus/.R/Makevars:1: *** missing separator. Stop.
ERROR: compilation failed for package ‘haven’
* removing ‘/home/mus/R/x86_64-pc-linux-gnu-library/3.4/haven’

The length of this message is significantly larger – I have merely truncated it for the purpose of this question.

My question is this: what could I be missing here? I don't think it should be so difficult to resolve, yet it is proving to be one of the single most complicated problems I have ever come up against and I cannot think of what it could possibly be.

Are there any tips and tricks that those of you who have had similar experiences can share?

How can I avoid these error messages? (Note that this also happens when I try running the same command from the Terminal.)

Also, if it helps:

> .libPaths()
[1] "/home/mus/R/x86_64-pc-linux-gnu-library/3.4" "/usr/local/lib/R/site-library"              
[3] "/usr/lib/R/site-library"                     "/usr/lib/R/library" 

Best Answer

Use pre-compiled packages when available

As it is true for general packages, so it is true for R packages. Use Ubuntu's application package download and install system to get R packages.

To find out if a particular R package is available in the R-CRAN repositories, open a terminal by pressing Ctrl+Alt+T and enter:

apt-cache search tidyverse

You will see a list of packages associated with tidyverse:

r-cran-sjmisc - GNU R package "Data and Variable Transformation Functions"
r-cran-tidyverse - GNU R package "Easily Install and Load the 'Tidyverse'"
r-cran-tidyquant - GNU R package "Tidy Quantitative Financial Analysis"
r-cran-rlang - GNU R package "Functions for Base Types and Core R and
r-cran-tidyselect - GNU R package "Select from a Set of Strings"
r-cran-sugrrants - GNU R package "Supporting Graphs for Analysing Time
r-cran-tidyimpute - GNU R package "Imputation the Tidyverse Way"
r-cran-pivot - GNU R package "'SQL' PIVOT and UNPIVOT"
r-cran-tidycensus - GNU R package "Load US Census Boundary and Attribute Data
r-cran-janitor - GNU R package "Simple Tools for Examining and Cleaning
r-cran-areal - GNU R package "Areal Weighted Interpolation"
r-cran-moderndive - GNU R package "Tidyverse-Friendly Introductory Linear

The package you are looking for is second in the list. All R packages have the prefix r-cran-.

To install the R package, enter:

sudo apt install r-cran-tidyverse

You will be asked for your password. When you enter the password, the cursor will not move and you will not see *******. This is normal in Ubuntu.

Installing R packages in this way has two benefits:

  1. It will keep fGarch up-to-date. Whenever fGarch is updated in R-Cran repository, it will be updated in your computer along with the system update process.
  2. All users of this computer will be able to use the fGarch package within R and RStudio.

See R and RStudio installation and package error for more details.

The error:

The error you are seeing is because curl is not installed in your Ubuntu. Ubuntu uses wget while other distributions use curl to download system packages. When you are trying to install a package from within R (or RStudio) it is trying to install an Ubuntu system package curl. This does not work, as RStudio does not have sudo privileges.

To solve this problem, install curl at the Ubuntu system level by:

sudo apt install curl

This will install curl in Ubuntu and allow R to use curl.

Hope this helps