Why some R packages can't be installed

1.7k Views Asked by At

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?

1

There are 1 best solutions below

0
Steffen Moritz On

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