简体   繁体   中英

Cannot install R packages on new Ubuntu Device

I am a medical doctor (so no computer science background at all) starting to get involved with bioinformatic analyses of big datasets and have used R on my private Windows laptop in the past without any problems.

My department now bought a new powerful Laptop to speed up the analyses and our bioinformatics core facility recommended using a Linux system (which I have never really used before), so now I have this great Ubuntu laptop but I'm getting a little frustrated with just setting up my R environment to start working. I've heard Linux needs some time to get used to and I'm up for the challenge and want to try to understand what I'm doing.

So the problem I have is that I cannot really install certain packages in R. As I said the laptop is brand new and installing R and RStudio was one of the first things I did without changing anything in the basic settings of the laptop. So I was very surprised that I keep getting errors in something as simple as installing those packages. For some reason some packages like

install.packages("tidyverse")

work fine, while others fail. So

install.packages("devtools")

gives me the following output

Installing package into ‘/home/jasper/R/x86_64-pc-linux-gnu-library/4.2’
(as ‘lib’ is unspecified)
also installing the dependencies ‘systemfonts’, ‘textshaping’, ‘ragg’, ‘pkgdown’

trying URL 'https://cloud.r-project.org/src/contrib/systemfonts_1.0.4.tar.gz'
Content type 'application/x-gzip' length 81757 bytes (79 KB)
==================================================
downloaded 79 KB

trying URL 'https://cloud.r-project.org/src/contrib/textshaping_0.3.6.tar.gz'
Content type 'application/x-gzip' length 35722 bytes (34 KB)
==================================================
downloaded 34 KB

trying URL 'https://cloud.r-project.org/src/contrib/ragg_1.2.4.tar.gz'
Content type 'application/x-gzip' length 427579 bytes (417 KB)
==================================================
downloaded 417 KB

trying URL 'https://cloud.r-project.org/src/contrib/pkgdown_2.0.7.tar.gz'
Content type 'application/x-gzip' length 871465 bytes (851 KB)
==================================================
downloaded 851 KB

trying URL 'https://cloud.r-project.org/src/contrib/devtools_2.4.5.tar.gz'
Content type 'application/x-gzip' length 374718 bytes (365 KB)
==================================================
downloaded 365 KB

* installing *source* package ‘systemfonts’ ...
** package ‘systemfonts’ successfully unpacked and MD5 sums checked
** using staged installation
Package fontconfig was not found in the pkg-config search path.
Perhaps you should add the directory containing `fontconfig.pc'
to the PKG_CONFIG_PATH environment variable
No package 'fontconfig' found
Package freetype2 was not found in the pkg-config search path.
Perhaps you should add the directory containing `freetype2.pc'
to the PKG_CONFIG_PATH environment variable
No package 'freetype2' found
Using PKG_CFLAGS=
Using PKG_LIBS=-lfontconfig -lfreetype
--------------------------- [ANTICONF] --------------------------------
Configuration failed to find the fontconfig freetype2 library. Try installing:
 * deb: libfontconfig1-dev (Debian, Ubuntu, etc)
 * rpm: fontconfig-devel (Fedora, EPEL)
 * csw: fontconfig_dev (Solaris)
 * brew: freetype (OSX)
If fontconfig freetype2 is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a fontconfig freetype2.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 MESSAGE] ---------------------------
<stdin>:1:10: fatal error: fontconfig/fontconfig.h: No such file or directory
compilation terminated.
--------------------------------------------------------------------
ERROR: configuration failed for package ‘systemfonts’
* removing ‘/home/jasper/R/x86_64-pc-linux-gnu-library/4.2/systemfonts’
Warning in install.packages :
  installation of package ‘systemfonts’ had non-zero exit status
ERROR: dependency ‘systemfonts’ is not available for package ‘textshaping’
* removing ‘/home/jasper/R/x86_64-pc-linux-gnu-library/4.2/textshaping’
Warning in install.packages :
  installation of package ‘textshaping’ had non-zero exit status
ERROR: dependencies ‘systemfonts’, ‘textshaping’ are not available for package ‘ragg’
* removing ‘/home/jasper/R/x86_64-pc-linux-gnu-library/4.2/ragg’
Warning in install.packages :
  installation of package ‘ragg’ had non-zero exit status
ERROR: dependency ‘ragg’ is not available for package ‘pkgdown’
* removing ‘/home/jasper/R/x86_64-pc-linux-gnu-library/4.2/pkgdown’
Warning in install.packages :
  installation of package ‘pkgdown’ had non-zero exit status
ERROR: dependency ‘pkgdown’ is not available for package ‘devtools’
* removing ‘/home/jasper/R/x86_64-pc-linux-gnu-library/4.2/devtools’
Warning in install.packages :
  installation of package ‘devtools’ had non-zero exit status

The downloaded source packages are in
    ‘/tmp/RtmpZcPwU9/downloaded_packages’

After looking online for a couple of days now, I believe that there is a problem with the directories or access to them. When I enter

.libPaths()

in R, it gives me

[1] "/home/jasper/R/x86_64-pc-linux-gnu-library/4.2" "/usr/local/lib/R/site-library"
[3] "/usr/lib/R/site-library" "/usr/lib/R/library"

So I started looking into this and tried to modify R_LIBS_USER part of the Renviron file as described here ( How do I change the default library path for R packages ) without any success.

When I tried installing another package, I got the message that the path is not writable and I read this might be a permission problem. So I used used chmod -R 777 on the four directories (which as far as I understood gives me all permissions to these folders) that showed up with.libPaths(), but no success either. Repeated reinstallation of R and RStudio did not help either.

Unfortunately my computer science skills quickly find their limit (even working with the terminal to be honest). Since I honestly do not really understand what I am doing and would like to do so while changing files in the root of this new laptop, I am hoping that you can help me out. Quitting and changing back to Windows is not an option for my ego:D.

Here is my sessionInfo():

R version 4.2.2 Patched (2022-11-10 r83330) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 20.04.5 LTS

Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0 LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=de_DE.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=de_DE.UTF-8
[6] LC_MESSAGES=en_US.UTF-8 LC_PAPER=de_DE.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C

attached base packages: [1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached): [1] compiler_4.2.2 fastmap_1.1.0 cli_3.4.1 htmltools_0.5.4 tools_4.2.2 rstudioapi_0.14 yaml_2.3.6 rmarkdown_2.19 [9] knitr_1.41 xfun_0.35 digest_0.6.31 rlang_1.0.6 evaluate_0.19

I would really appreciate your help!

Thanks a lot,

Jasper

I had this same problem recently when trying to install devtools on a kali linux virtual box.

The way I got around it was to install dev tool directly from the linux command line (terminal) using:

sudo apt-get install r-cran-devtools

This should work on Ubuntu too. Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM