problems installing ggplot2

I am running R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out" in RStudio 1.3.1093 on Ubuntu 18.04. I tried to install the package ggplot2 when I ran into the following error messages:

Installing package into ‘/home/nick/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
also installing the dependencies ‘testthat’, ‘isoband’

trying URL 'https://cloud.r-project.org/src/contrib/testthat_3.0.1.tar.gz'
Content type 'application/x-gzip' length 678199 bytes (662 KB)
==================================================
downloaded 662 KB

trying URL 'https://cloud.r-project.org/src/contrib/isoband_0.2.3.tar.gz'
Content type 'application/x-gzip' length 1902568 bytes (1.8 MB)
==================================================
downloaded 1.8 MB

trying URL 'https://cloud.r-project.org/src/contrib/ggplot2_3.3.3.tar.gz'
Content type 'application/x-gzip' length 3058840 bytes (2.9 MB)
==================================================
downloaded 2.9 MB

* installing *source* package ‘testthat’ ...
** package ‘testthat’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -DCOMPILING_TESTTHAT     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-7BvS0x/r-base-4.0.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c init.c -o init.o
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -DCOMPILING_TESTTHAT     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-7BvS0x/r-base-4.0.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c reassign.c -o reassign.o
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -DCOMPILING_TESTTHAT     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-7BvS0x/r-base-4.0.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c test-catch.cpp -o test-catch.o
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -DCOMPILING_TESTTHAT     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-7BvS0x/r-base-4.0.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c test-example.cpp -o test-example.o
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -DCOMPILING_TESTTHAT     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-7BvS0x/r-base-4.0.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c test-runner.cpp -o test-runner.o
g++ -std=gnu++11 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o testthat.so init.o reassign.o test-catch.o test-example.o test-runner.o -L/usr/lib/R/lib -lR
installing to /home/nick/R/x86_64-pc-linux-gnu-library/4.0/00LOCK-testthat/00new/testthat/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘testthat’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/home/nick/R/x86_64-pc-linux-gnu-library/4.0/00LOCK-testthat/00new/testthat/libs/testthat.so':
  /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by /home/nick/R/x86_64-pc-linux-gnu-library/4.0/00LOCK-testthat/00new/testthat/libs/testthat.so)
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/nick/R/x86_64-pc-linux-gnu-library/4.0/testthat’
Warning in install.packages :
  installation of package ‘testthat’ had non-zero exit status
ERROR: dependency ‘testthat’ is not available for package ‘isoband’
* removing ‘/home/nick/R/x86_64-pc-linux-gnu-library/4.0/isoband’
Warning in install.packages :
  installation of package ‘isoband’ had non-zero exit status
ERROR: dependency ‘isoband’ is not available for package ‘ggplot2’
* removing ‘/home/nick/R/x86_64-pc-linux-gnu-library/4.0/ggplot2’
Warning in install.packages :
  installation of package ‘ggplot2’ had non-zero exit status

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

I figured from the first error message that the problem was testthat is missing. I went here and tried running this command in hopes that I could install these prereqs to ggplot2
withr::with_makevars(c(PKG_LIBS = "-liconv"), install.packages("testthat"), assignment = "+=")
Yet, I still run into more errors:

Installing package into ‘/home/nick/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/testthat_3.0.1.tar.gz'
Content type 'application/x-gzip' length 678199 bytes (662 KB)
==================================================
downloaded 662 KB

* installing *source* package ‘testthat’ ...
** package ‘testthat’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -DCOMPILING_TESTTHAT     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-7BvS0x/r-base-4.0.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c init.c -o init.o
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -DCOMPILING_TESTTHAT     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-7BvS0x/r-base-4.0.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c reassign.c -o reassign.o
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -DCOMPILING_TESTTHAT     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-7BvS0x/r-base-4.0.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c test-catch.cpp -o test-catch.o
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -DCOMPILING_TESTTHAT     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-7BvS0x/r-base-4.0.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c test-example.cpp -o test-example.o
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -DCOMPILING_TESTTHAT     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-7BvS0x/r-base-4.0.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c test-runner.cpp -o test-runner.o
g++ -std=gnu++11 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o testthat.so init.o reassign.o test-catch.o test-example.o test-runner.o -liconv -L/usr/lib/R/lib -lR
/usr/bin/ld: cannot find -liconv
collect2: error: ld returned 1 exit status
/usr/share/R/share/make/shlib.mk:10: recipe for target 'testthat.so' failed
make: *** [testthat.so] Error 1
ERROR: compilation failed for package ‘testthat’
* removing ‘/home/nick/R/x86_64-pc-linux-gnu-library/4.0/testthat’
Warning in install.packages :
  installation of package ‘testthat’ had non-zero exit status

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

I do not know a lot about R, so any assistance is greatly appreciated.

It seems you are missing a system dependency or you have an incompatible version, try installing this library from a system terminal.

sudo apt install libstdc++6
1 Like

So, I went ahead and ran the command,

Reading package lists... Done
Building dependency tree       
Reading state information... Done
libstdc++6 is already the newest version (8.4.0-1ubuntu1~18.04).
libstdc++6 set to manually installed.
The following packages were automatically installed and are no longer required:
  linux-headers-5.4.0-62-generic linux-hwe-5.4-headers-5.4.0-42
  linux-hwe-5.4-headers-5.4.0-53 linux-hwe-5.4-headers-5.4.0-56
  linux-hwe-5.4-headers-5.4.0-58 linux-hwe-5.4-headers-5.4.0-59
  linux-hwe-5.4-headers-5.4.0-60 linux-hwe-5.4-headers-5.4.0-62
  linux-image-5.4.0-62-generic linux-modules-5.4.0-62-generic
  linux-modules-extra-5.4.0-62-generic python-decorator python-numpy
  python-olefile python-pil
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 11 not upgraded.

It seems that I already have libstdc++6. This outputted the same error in Rstudio

Since the initial error message shows things failing on isoband and testhat, you might attempt to installs those first, and then retry installing ggplot2.

install.packages('isoband')
install.packages('testhat')

I get these loading errors when I attempt to install isoband

Installing package into ‘/home/nick/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
also installing the dependency ‘testthat’

trying URL 'https://cloud.r-project.org/src/contrib/testthat_3.0.1.tar.gz'
Content type 'application/x-gzip' length 678199 bytes (662 KB)
==================================================
downloaded 662 KB

trying URL 'https://cloud.r-project.org/src/contrib/isoband_0.2.3.tar.gz'
Content type 'application/x-gzip' length 1902568 bytes (1.8 MB)
==================================================
downloaded 1.8 MB

* installing *source* package ‘testthat’ ...
** package ‘testthat’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -DCOMPILING_TESTTHAT     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-7BvS0x/r-base-4.0.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c init.c -o init.o
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -DCOMPILING_TESTTHAT     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-7BvS0x/r-base-4.0.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c reassign.c -o reassign.o
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -DCOMPILING_TESTTHAT     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-7BvS0x/r-base-4.0.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c test-catch.cpp -o test-catch.o
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -DCOMPILING_TESTTHAT     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-7BvS0x/r-base-4.0.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c test-example.cpp -o test-example.o
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -DCOMPILING_TESTTHAT     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-7BvS0x/r-base-4.0.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c test-runner.cpp -o test-runner.o
g++ -std=gnu++11 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o testthat.so init.o reassign.o test-catch.o test-example.o test-runner.o -L/usr/lib/R/lib -lR
installing to /home/nick/R/x86_64-pc-linux-gnu-library/4.0/00LOCK-testthat/00new/testthat/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘testthat’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/home/nick/R/x86_64-pc-linux-gnu-library/4.0/00LOCK-testthat/00new/testthat/libs/testthat.so':
  /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by /home/nick/R/x86_64-pc-linux-gnu-library/4.0/00LOCK-testthat/00new/testthat/libs/testthat.so)
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/nick/R/x86_64-pc-linux-gnu-library/4.0/testthat’
Warning in install.packages :
  installation of package ‘testthat’ had non-zero exit status
ERROR: dependency ‘testthat’ is not available for package ‘isoband’
* removing ‘/home/nick/R/x86_64-pc-linux-gnu-library/4.0/isoband’
Warning in install.packages :
  installation of package ‘isoband’ had non-zero exit status

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

@EconomiCurtis My gcc --version says
gcc.exec (GCC) 9.2.0
Any more suggestions?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.