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.
- 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 - Set up a storage volume, then upload the SSL certificate file:
-
Set up the
cc-homestorage volume for customizations. For instructions, see Setting up a storage volume to store customizations for the common core services. - Upload the SSL certificate file from your local machine to the shared location at
/cc-home/_global_/security/customer-truststoreson the Cloud Pak for Data cluster.
-
- Check the connectivity in RStudio session:
- 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") - Run the test commands as given in Step 5 and Step 6 to check if your repository is responding.
- Set the configuration temporarily by using the following
commands:
- 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
cranRepoURLandcurlCABundleNameto the RStudio custom resources.Note: You must update all RStudio custom resources (rstudio-cr,ibm-cpd-rstudio-rt231, andibm-cpd-rstudio-rt222) by addingcranRepoURLandcurlCABundleName.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.crtto 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" EOFcat << 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" EOFcat << 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 - 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') - 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")