TOPIC: CMAKE
Installing R and the Tidyverse in a SAS Analytics Pro on Viya container
Because I wanted to use PROC R, which SAS introduced as a new procedure in SAS Viya for using R methods and packages within a SAS process and moving data between SAS and R, R had to be available where SAS runs. This needs SAS Viya 2026.03 or later, and a stand-alone R script is run with a statement of the form proc R infile=...;.
That meant installing R in a container running SAS Analytics Pro on Viya, which SAS describes as a cloud-ready, containerised version of SAS Analytics Pro. This is because R is not included on the Docker image from which the container is created, so it has to be added to every new container. That is why the whole installation has to be repeatable.
With R 4.5.2 in place, adding the Tidyverse was next. It looks like a one line install on a minimal Linux system, yet it produced a long trail of errors that was far longer than the problem behind it. The explanation is that the {tidyverse} is a meta-package, which lists 29 other packages as imports. Several of those, directly or indirectly, compile C or C++ code that needs system libraries and development headers, and a minimal system has none of them. When one package fails, everything that depends on it fails too, which is why some much output is produced.
Reading the Output for Root Causes
The installation was run with the command below, with all output sent to a log file so that it could be searched afterwards. Having the output in a file matters here because each retry needs a fresh log to compare against the last.
/opt/R/4.5.2/bin/Rscript -e 'install.packages("tidyverse", repos="https://cloud.r-project.org")' > /tmp/tidyverse-install.log 2>&1
Searching that file for the underlying failures is quicker than treating every error as a separate fault. The command below brings the main messages together, and it is worth running again after each attempt.
grep -iE 'error:|fatal error|not found|configuration failed|non-zero exit status' /tmp/tidyverse-install.log
The Four Packages That Failed First
The first results showed four packages failing to find system components. The {openssl} package could not compile because `openssl/opensslv.h` was missing, and its documentation says that Fedora, CentOS and RHEL systems need `openssl-devel`. For {systemfonts}, the gaps were `fontconfig` and `freetype2`, which are precisely the two requirements it declares, and configuration stopped because `fontconfig/fontconfig.h` was unavailable.
The {fs} package reported that libuv was not found and that the cmake command was missing. That fits its declared requirements, which are libuv-devel on RPM systems or, alternatively, CMake and GNU make to build the bundled copy of libuv. Meanwhile, {xml2} could not find libxml-2.0, and the compiler reported that libxml/tree.h was absent, which points to the libxml2-devel package on RPM systems.
How Four Failures Became Dozens
These four failures explain most of the remaining messages. The {sass} package imports {fs}, {bslib} imports {sass} and {rmarkdown} imports {bslib}, so a missing {fs} takes out three more packages in one go.
The {openssl} package has a similar reach, since {httr} imports it, as does {gargle}. From there the damage spreads to {googledrive} and {googlesheets4}, which both import {gargle} and {httr}. The {reprex} package imports both {fs} and {rmarkdown}, while {rvest} imports {httr} and {xml2}. With all of those unavailable, the Tidyverse itself was reported as unavailable.
This is the useful lesson from the output. A failure reported against a top-level package rarely names the original cause, so fixing the four packages at the bottom is much quicker than repairing each downstream package in turn.
Enabling the UBI Repositories
The environment provided the public UBI repositories, so the system packages were installed with every other repository disabled. That meant enabling ubi-9-baseos-rpms, ubi-9-appstream-rpms and ubi-9-codeready-builder-rpms explicitly. The last of those matters because development packages are the kind of content that the CodeReady Linux Builder repository exists to provide for developers.
The first request also asked for libuv-devel, and DNF refused it with "No match for argument: libuv-devel". That meant the package was not available under that name from the enabled repositories, and it did not show that {fs} could not be built. Since {fs} can build its bundled libuv when CMake is present, the command was adjusted to leave libuv-devel out, as shown below.
dnf --disablerepo='*'
--enablerepo=ubi-9-baseos-rpms
--enablerepo=ubi-9-appstream-rpms
--enablerepo=ubi-9-codeready-builder-rpms
install
openssl-devel
fontconfig-devel
freetype-devel
cmake
libxml2-devel
A Second Layer with {textshaping}
After that install, the same search of the new output gave a different picture. The output still contained messages saying that libuv was not found by `pkg-config`, but {fs} appeared to have compiled, which supports the idea that CMake had been the real obstacle. The earlier failures for {openssl}, {systemfonts} and {xml2} no longer appeared among the blockers.
The next failure came from {textshaping}, where configuration could not find FriBidi and compilation stopped on fribidi.h. The output said "Package fribidi was not found in the pkg-config search path", which matches the package declaring freetype2, harfbuzz and fribidi as requirements. The next step added fribidi-devel and harfbuzz-devel from the same three repositories, and after another retry {textshaping} appeared to have installed.
dnf --disablerepo='*'
--enablerepo=ubi-9-baseos-rpms
--enablerepo=ubi-9-appstream-rpms
--enablerepo=ubi-9-codeready-builder-rpms
install
fribidi-devel
harfbuzz-devel
A Third Layer with the Image Libraries
The remaining failure was in {ragg}, which imports {textshaping} and which the Tidyverse imports in turn. Its configuration reported that `pkg-config` could not find libtiff-4, libjpeg, libwebp or libwebpmux, and that one or more of freetype2, libpng, libtiff-4, libjpeg, libwebp and libwebpmux were missing. That list lines up with the package's declared requirements of freetype2, libpng, libtiff, libjpeg, libwebp and libwebpmux.
The compiler also complained that ft2build.h was missing, even though freetype-devel had already been installed. A working explanation is that this was a side effect of the combined configuration check failing, but that remains a possibility and not a confirmed diagnosis. The firmer evidence was the absence of the TIFF, JPEG and WebP development libraries, so the next step added those along with libpng-devel.
dnf --disablerepo='*'
--enablerepo=ubi-9-baseos-rpms
--enablerepo=ubi-9-appstream-rpms
--enablerepo=ubi-9-codeready-builder-rpms
install
libtiff-devel
libjpeg-turbo-devel
libwebp-devel
libpng-devel
One Script to Add R, the Tidyverse and {arrow} to the UBI 9 Image
The commands above were stepping stones, and the end result was a single bash script that I could run when building the image. It stops unless the operating system is version 9 and downloads the R 4.5.2 RPM only when R is not already present, using one of the precompiled binaries that Posit publishes for Linux servers. It then installs every system library from the three UBI repositories before installing {R6}, {tidyverse} and {arrow}, but only the ones that are missing. The {arrow} package is needed for this PROC R setup, which is why it sits in that list. A SAS employee write-up of the SAS documentation names {R6}, {arrow}, {haven}, {plotly} and {svglite}, although it does not say whether any of them are required. A vignette for the {OECDsppps} R package goes further and says that R with {R6}, {arrow}, {haven}, {plotly}, {svglite} and {gt} is necessary for full PROC R functionality, but it is also third-party material and not SAS documentation. The {haven} package already arrives with the Tidyverse, which also suits the examples that SAS publishes, since they load it with library(tidyverse).
Two details are worth pointing out. The R step ends with stopifnot, so the script fails if any of the three packages cannot be loaded, and the final lines print the R version, the R home directory and the {R6} version as a check. The system package list also gains libatomic, which did not appear in any of the errors earlier in this article, and the RPM is installed with the signature check for local packages switched off, which is a trade-off to be aware of.
With R installed this way, PROC R worked as hoped on the SAS Analytics Pro on Viya image. The script can safely be run again, since it skips the R download when the binary exists and skips any package that already loads.
The script follows in full below. It is saved on the host as install_r.sh.
#!/bin/bash
set -euo pipefail
R_VERSION="4.5.2"
R_PREFIX="/opt/R/${R_VERSION}"
R_RPM="/tmp/R-${R_VERSION}.rpm"
R_URL="https://cdn.posit.co/r/rhel-9/pkgs/R-${R_VERSION}-1-1.x86_64.rpm"
# Check operating system compatibility
source /etc/os-release
if [[ "${VERSION_ID%%.*}" != "9" ]]; then
echo "Unsupported operating system: ${PRETTY_NAME}"
exit 1
fi
# Download and install R
if [[ ! -x "${R_PREFIX}/bin/R" ]]; then
curl -fL --retry 3 "$R_URL" -o "$R_RPM"
dnf -y
--disablerepo='*'
--enablerepo=ubi-9-baseos-rpms
--enablerepo=ubi-9-appstream-rpms
--enablerepo=ubi-9-codeready-builder-rpms
--setopt=localpkg_gpgcheck=0
install "$R_RPM"
rm -f "$R_RPM"
fi
# Install system dependencies
dnf -y
--disablerepo='*'
--enablerepo=ubi-9-baseos-rpms
--enablerepo=ubi-9-appstream-rpms
--enablerepo=ubi-9-codeready-builder-rpms
install
openssl-devel
fontconfig-devel
freetype-devel
cmake
libxml2-devel
fribidi-devel
harfbuzz-devel
libtiff-devel
libjpeg-turbo-devel
libwebp-devel
libpng-devel
libatomic
# Install required R packages
"${R_PREFIX}/bin/Rscript" -e '
packages <- c("R6", "tidyverse", "arrow")
missing <- packages[!vapply(
packages, requireNamespace, logical(1), quietly = TRUE
)]
if (length(missing) > 0) {
install.packages(missing,
repos = "https://cloud.r-project.org")
}
stopifnot(all(vapply(
packages, requireNamespace, logical(1), quietly = TRUE
)))
'
# Verify installation
"${R_PREFIX}/bin/R" --version
"${R_PREFIX}/bin/R" RHOME
"${R_PREFIX}/bin/Rscript" -e 'print(packageVersion("R6"))'
echo "R installation completed successfully."
The script is written on the host and copied into the container by the script that updates the image and launches it, so nothing needs installing by hand. The docker exec command runs a new command in a running container, where -u root sets the user. Here sas-analytics-pro is the container name used in the SAS Analytics Pro deployment guide, so substitute the name of your own container if it differs.
# Installing R
docker cp install_r.sh sas-analytics-pro:/tmp/install_r.sh
docker exec -u root sas-analytics-pro bash /tmp/install_r.sh
The cost that remains is time because the installation now runs whenever a container is created. On Linux, the Arrow documentation says that install.packages retrieves the source version of {arrow} and compiles both the R package and libarrow from source by default, so each launch may take a while.
The answer is to keep two versions of the launch script. One includes the two lines above and builds R, while the other leaves them out and is the one to use when a faster start matters. A container started with the second script has no R installed, so PROC R will not work in it until the first script has been used.
A derived image would remove the wait altogether, with a Dockerfile that starts from the SAS Analytics Pro base image and runs the installation script during the build. Other vendors already work this way, and Domino describes pulling the base image for SAS Analytics Pro and then using a Dockerfile to build a new image from it. That approach is untested here, but it would move the compile step to build time.
The approach behind the script is worth keeping. Start from the earliest failures, map each failing R package to the system libraries it declares, install the matching -devel packages and read the fresh output before deciding what to do next. Each pass turned a broad failure to install the Tidyverse into a smaller and more specific problem, which is far easier to solve than a list of dozens of unrelated looking errors.