Problem
When trying to use CRAN to install the R package Survminer
on a Databricks cluster using the Libraries section, you encounter an issue and receive an error message.
'installation of package ‘<package-name>’ had non-zero exit status'
Cause
The Survminer
package is not available for R version 4.3.2 used in the Databricks cluster. Attempts to install the package and its dependencies directly from CRAN or GitHub fail due to compatibility issues with the R version. Additionally, network restrictions or CRAN mirror issues may prevent you from installing the package.
Solution
- Use an init script to install a compatible version of R and the necessary dependencies, such as the following example.
#!/bin/bash
# Update the package list
sudo apt-get update
# Install R
sudo apt-get install -y r-base
# Install necessary dependencies for R packages
sudo apt-get install -y libcurl4-openssl-dev libxml2-dev libssl-dev
# Install remotes package to enable installation of specific versions
sudo R -e "install.packages('remotes', repos = 'http://cran.us.r-project.org')"
# Install specific version of Matrix package
sudo R -e "remotes::install_version('Matrix', version = '1.6-2', repos = 'http://cran.us.r-project.org')"
# Install Survminer package
sudo R -e "install.packages('survminer', repos = 'http://cran.us.r-project.org')"
- Attach the init script to your cluster.
- Restart the cluster.
If the issue persists, check for network restrictions or firewall rules that may be blocking access to the CRAN repository. Ensure that the proxy settings are correctly configured if your network uses a proxy.
If needed, you can try installing the package from a known CRAN mirror directly in the notebook using the following command.
install.packages('survminer', repos = 'http://cran.us.r-project.org')