Adding libraries from CRAN repositories

You can install libraries from any custom CRAN repositories, for example from the Nexus repository, to use in RStudio. To install R packages from a custom CRAN repository securely, the SSL certificate for the repository must be installed on IBM® Software Hub and the RStudio custom resource must be updated to enable access to the certificate.

The following steps show you how to use a Nexus CRAN repository securely. However, the steps apply to any custom CRAN repository that uses custom certifications.

To enable users to install libraries from a Nexus CRAN repository securely in R Studio, do the following:
  1. Retrieve the SSL certificate to the Nexus repository server and store the certificate on your local machine:
    echo quit | openssl s_client -showcerts -servername <HOST-OF-REPO> -connect <HOST-OF-REPO>:443 > nexuscert.crt
  2. Set up a storage volume, then upload the SSL certificate file:
    1. Set up the cc-home storage volume for customizations. For instructions, see Setting up a storage volume to store customizations for the common core services.

    2. Upload the SSL certificate file from your local machine to the shared location at /cc-home/_global_/security/customer-truststores on the Cloud Pak for Data cluster.
  3. Check the connectivity in RStudio session:
    1. Set the configuration temporarily by using the following commands:
      Sys.setenv(CURL_CA_BUNDLE="/cc-home/_global_/security/customer-truststores/YOUR-CERTIFICATE.crt")
      options(repos = c(CRAN="YOUR-REPOSITORY-URL"),download.file.method="curl")
    2. Run the test commands as given in Step 5 and Step 6 to check if your repository is responding.
  4. If the previous step is successful, make the configuration permanent. Locate the certificate to enable secure access for users to the Nexus repository from RStudio by adding cranRepoURL and curlCABundleName to the RStudio custom resources.
    Note: You must update all RStudio custom resources (rstudio-cr, ibm-cpd-rstudio-rt231, and ibm-cpd-rstudio-rt222) by adding cranRepoURL and curlCABundleName.

    Generate the list of custom resources that you have by using this command: oc get rstudioaddon.

    For example, add:
    cranRepoURL=https://<HOST-OF-REPO>/nexus3/repository/cran
    curlCABundleName=nexuscert.crt
    to the custom resources, as follows:
    cat << EOF | oc apply -f -
    apiVersion: rstudio.cpd.ibm.com/v1beta1
    kind: RStudioAddon
    metadata:
      name: rstudio-cr
      namespace: cpd-instance
    spec:
      license:
        license: "Enterprise"
        accept: true
      cranRepoURL: "https://<HOST-OF-REPO>/nexus3/repository/cran"
      curlCABundleName: "nexuscert.crt"
    EOF
    cat << EOF | oc apply -f -
    apiVersion: rstudio.cpd.ibm.com/v1beta1
    kind: RStudioAddon
    metadata:
      name: ibm-cpd-rstudio-rt222
      namespace: cpd-instance
    spec:
      license:
        license: "Enterprise"
        accept: true
      cranRepoURL: "https://<HOST-OF-REPO>/nexus3/repository/cran"
      curlCABundleName: "nexuscert.crt"
    EOF
    cat << EOF | oc apply -f -
    apiVersion: rstudio.cpd.ibm.com/v1beta1
    kind: RStudioAddon
    metadata:
      name: ibm-cpd-rstudio-rt231
      namespace: cpd-instance
    spec:
      license:
        license: "Enterprise"
        accept: true
      cranRepoURL: "https://<HOST-OF-REPO>/nexus3/repository/cran"
      curlCABundleName: "nexuscert.crt"
    EOF
  5. Stop any active RStudio runtimes and launch RStudio with a reset workspace. Use these commands to test on R console:
    system("ls -l /cc-home/_global_/security/customer-truststores/")
    Sys.getenv('CURL_CA_BUNDLE')
    getOption('repos')
  6. Now R Studio users can install packages from the Nexus CRAN repository in RStudio in a secure way. For example, to install glmnet, they can enter: install.packages("glmnet")