'Keras installation failed with Rstudio RcppTOML had non-zero exit status

I am struggling to install keras on my Rstudio version 2021.09.2 Build 382 (R version 3.6.0 (2019-04-26)) on Linux Centos 7. I am having this error message:

ERROR: compilation failed for package ‘RcppTOML’
* removing ‘/usr/lib64/R/library/RcppTOML’
ERROR: dependency ‘RcppTOML’ is not available for package ‘reticulate’
* removing ‘/usr/lib64/R/library/reticulate’
ERROR: dependency ‘reticulate’ is not available for package ‘tfautograph’
* removing ‘/usr/lib64/R/library/tfautograph’
ERROR: dependency ‘reticulate’ is not available for package ‘tfruns’
* removing ‘/usr/lib64/R/library/tfruns’
ERROR: dependencies ‘reticulate’, ‘tfruns’, ‘tfautograph’ are not available for package ‘tensorflow’
* removing ‘/usr/lib64/R/library/tensorflow’
ERROR: dependencies ‘reticulate’, ‘tensorflow’, ‘tfruns’ are not available for package ‘keras’
* removing ‘/usr/lib64/R/library/keras’

I tried to install manually directly from the tar, but I still have the same error.

1: In install.packages("keras") :
  installation of package ‘RcppTOML’ had non-zero exit status
2: In install.packages("keras") :
  installation of package ‘reticulate’ had non-zero exit status
3: In install.packages("keras") :
  installation of package ‘tfautograph’ had non-zero exit status
4: In install.packages("keras") :
  installation of package ‘tfruns’ had non-zero exit status
5: In install.packages("keras") :
  installation of package ‘tensorflow’ had non-zero exit status
6: In install.packages("keras") :
  installation of package ‘keras’ had non-zero exit status

Any idea how to solve it? Thanks.



Solution 1:[1]

I finally understood, there is a bug on CentOS 7: RcppTOML fails to compile with g++ 4.8.5 (20150623), but installs with g++ 5.3.1 (20160406) from scl-devtoolset-4.

sudo yum install centos-release-scl
sudo yum install devtoolset-7-gcc*
scl enable devtoolset-7 bash

These lines fixed the issue

Solution 2:[2]

As described in the comments the older version of RcppTOML also works; This is a lighter stack then the accepted answer.

install.packages("devtools")
require(devtools)
install_version("RcppTOML", version = "0.1.3", repos = "http://cran.us.r-project.org")

To install an older version the easiest way is to use devtools.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user979974
Solution 2 SvennD