1

I've been using R for a while and everything was normal when installing packages. Recently, I upgraded R on my Ubuntu 16.04 from 3.4.4 to 4.0.2 and then I tried to install the package imputeTS as

> install.packages("imputeTS")
Installing package into ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
also installing the dependencies ‘png’, ‘gridtext’, ‘ggtext’

trying URL 'https://cloud.r-project.org/src/contrib/png_0.1-7.tar.gz'
Content type 'application/x-gzip' length 24990 bytes (24 KB)
==================================================
downloaded 24 KB

trying URL 'https://cloud.r-project.org/src/contrib/gridtext_0.1.1.tar.gz'
Content type 'application/x-gzip' length 441462 bytes (431 KB)
==================================================
downloaded 431 KB

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

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

* installing *source* package ‘png’ ...
** package ‘png’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG      `libpng-config --cflags` -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c read.c -o read.o
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG      `libpng-config --cflags` -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c write.c -o write.o
gcc -std=gnu99 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o png.so read.o write.o -L/home/.../anaconda/lib -lpng16 -lm -lz -lm -L/usr/lib/R/lib -lR
installing to /home/.../R/x86_64-pc-linux-gnu-library/4.0/00LOCK-png/00new/png/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘png’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/home/.../R/x86_64-pc-linux-gnu-library/4.0/00LOCK-png/00new/png/libs/png.so':
  libpng16.so.16: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/png’
ERROR: dependency ‘png’ is not available for package ‘gridtext’
* removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/gridtext’
ERROR: dependency ‘gridtext’ is not available for package ‘ggtext’
* removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/ggtext’
ERROR: dependency ‘ggtext’ is not available for package ‘imputeTS’
* removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/imputeTS’

The downloaded source packages are in
    ‘/tmp/RtmpZubgYt/downloaded_packages’
Warning messages:
1: In install.packages("imputeTS") :
  installation of package ‘png’ had non-zero exit status
2: In install.packages("imputeTS") :
  installation of package ‘gridtext’ had non-zero exit status
3: In install.packages("imputeTS") :
  installation of package ‘ggtext’ had non-zero exit status
4: In install.packages("imputeTS") :
  installation of package ‘imputeTS’ had non-zero exit status

Then

> library(imputeTS)
Error in library(imputeTS) : there is no package called ‘imputeTS’

I tried to install the same package as install.packages("imputeTS", dependencies = TRUE) but this gave me the same result installation of package ‘imputeTS’ had non-zero exit status

Following, I tried to install the packages Hmisc and mice. The same result was for the first package where as mice was installed successfully!

Two more comments, the first is this statement (as ‘lib’ is unspecified) started to appear just after upgrading R. The second, I am not sure if related, is that there is no space on my linux!

So how could I install the needed packages successfuly?

  • relevant / possible duplicate : https://stackoverflow.com/q/20671814/4137985 – Cath Sep 22 '20 at 10:28
  • Thanks @Cath for the link. So, to install the packages imputeTS and Hmisc, how should I fill the code ' sudo apt-get install lib????.-openssl-dev lib????-dev ' – Sophie Allan Sep 22 '20 at 10:38
  • @Cath Additionally, Would you please why the library path changed once I upgraded R or if there is a relation ? – Sophie Allan Sep 22 '20 at 10:40
  • See this [AskUbuntu post](https://askubuntu.com/questions/701246/libpng16-so-16-not-found-how-to-get-it) about the installation of `libpng16.so.16`. – Rui Barradas Sep 22 '20 at 10:42
  • As for `lib`, you can set it with `install.packages("pkgname", lib = path/to/lib)`. Or you can make it permanent by finding file `Rprofile.site` and editing it. What does `.libPaths()` return? – Rui Barradas Sep 22 '20 at 10:45
  • Thanks @RuiBarradas for your comment. .libPaths() returns [1] "/home/.../R/x86_64-pc-linux-gnu-library/4.0" [2] "/usr/local/lib/R/site-library" [3] "/usr/lib/R/site-library" [4] "/usr/lib/R/library" But I've never changed the path before or after upgrading R.This (as ‘lib’ is unspecified) started to appear after upgrading. How can I solve this issue? – Sophie Allan Sep 22 '20 at 10:50
  • I would do `install.packages("pkgname", lib = .libPath()[2])` in order to have all packages in the same library, independent of the R version. Other directories could be 3 and 4 but not `.libPaths()[1]`. You can set this in your `Rprofile.site` file with `.libPaths(c("/usr/local/lib/R/site-library", "/usr/lib/R/site-library", "/usr/lib/R/library" ))`. – Rui Barradas Sep 22 '20 at 10:57
  • Thanks @RuiBarradas. The problem is solved using the link you added! I just did `(sudo apt-get install libpng16-16)` before installing the packages and it worked. – Sophie Allan Sep 22 '20 at 11:36

1 Answers1

0

Just a wrap up that people can find the correct answer given in the comments better and understand the error messages

This is no problem related specifically to the imputeTS package.

This can be seen in this part of the error message

Error: package or namespace load failed for ‘png’ in dyn.load(file, DLLpath = DLLpath, ...): unable to load shared object '/home/.../R/x86_64-pc-linux-gnu-library/4.0/00LOCK-png/00new/png/libs/png.so': libpng16.so.16: cannot open shared object file: No such file or directory

The error actually occurs while trying to install the png package.

How is this related to the imputeTS package?

You can see this here:

ERROR: loading failed

  • removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/png’ ERROR: dependency ‘png’ is not available for package ‘gridtext’
  • removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/gridtext’ ERROR: dependency ‘gridtext’ is not available for package ‘ggtext’
  • removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/ggtext’ ERROR: dependency ‘ggtext’ is not available for package ‘imputeTS’
  • removing ‘/home/.../R/x86_64-pc-linux-gnu-library/4.0/imputeTS’

R packages build on each other and import functions of other packages. In this case imputeTS imports ggtext, which imports gridtext, which imports png.

So quite a sequence of dependencies and if installation of png fails, this affects all the other packages.

Luckily this part of the error message also gives a hint, what could be wrong:

unable to load shared object '/home/.../R/x86_64-pc-linux-gnu-library/4.0/00LOCK-png/00new/png/libs/png.so': libpng16.so.16: cannot open shared object file: No such file or directory

There is a library missing on which the png package itself depends on. Without this library the installation of png will fail and cause all these mentioned issues.

So just install the library like this:

sudo apt-get install libpng16-16
Steffen Moritz
  • 7,277
  • 11
  • 36
  • 55