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:
You will see a list of packages associated with
tidyverse
: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:
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:
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 useswget
while other distributions usecurl
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 packagecurl
. This does not work, as RStudio does not havesudo
privileges.To solve this problem, install
curl
at the Ubuntu system level by:This will install
curl
in Ubuntu and allow R to usecurl
.Hope this helps