ARTIFACTORY: Configure CRAN remote repository & RGui/RConsole with Artifactory

ARTIFACTORY: Configure CRAN remote repository & RGui/RConsole with Artifactory

AuthorFullName__c
Md Mohsin Ali
articleNumber
000006230
ft:sourceType
Salesforce
FirstPublishedDate
2024-11-11T09:21:10Z
lastModifiedDate
2024-11-11
VersionNumber
2

Overview

Artifactory is a universal repository manager that can host and manage various types of packages, including R packages.
Configuring a CRAN remote repository with Artifactory provides a central location to manage R packages, streamline development, and ensure consistency across different environments.
This article outlines the steps necessary to set up Artifactory as a CRAN remote repository and how to configure RGui or RConsole to use this repository for installing R packages.



Prerequisites

1. An instance of JFrog Artifactory (either self-hosted or cloud)
2. Administrative access to the Artifactory instance
3. R installed on the local machine (RGui or RConsole)

Step 1: Create a CRAN Remote Repository in Artifactory

4. Log in to Artifactory : Use the administrative credentials to log in to the Artifactory instance.
5. Access the Admin Panel : Click on the Administration tab
6. Create a Repository :

  1. Select Repositories from the menu.
  2. Click on Create a Repostory, select Remote.
  3. Select repository type as “CRAN” to create a new remote repository.

7. Configure the Repository :

  1. Repository Key : Provide a unique name for the repository (e.g., remote-cran).
  2. URL : For the URL, enter the CRAN repository URL (e.g., https://cran.r-project.org).
  3. Advanced Settings : Configure any additional settings according to the requirements, such as cache settings, handling of metadata, or proxy settings.

8. Create Remote Repository: Click Create Remote Repository to create it. Here is an example screenshot for the reference. 


User-added image 

9. After the successful creation of the cran-remote repository, we can view it by navigation to Application Panel -> Artifactory -> Artifacts -> cran-remote

10. To generate the Cran client configurations, click on Set Me Up, and unlock by providing the credentials. After successful authentication, the configuration will be populated for us to copy and use.

User-added image 

On R Client

1. Login/Connect to the R server/client
2. Copy the configuration from Artifactory (step 4: On-Artifactory) and paste it on the R terminal

R version 4.1.2 (2021-11-01) -- "Bird Hippie"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
>
> local({
        r <- list("cran-remote" = "https://<username>:<token>@<artURL>/artifactory/cran-remote/")
        options(repos = r)
})
>


3. Now, install an R package(Ex: askpass)

> install.packages("askpass")
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)


4. Client output:

trying URL 'https://<username>:<token>@<artURL>/artifactory/cran-remote/src/contrib/askpass_1.2.0.tar.gz'
Content type 'application/x-gzip' length 6040 bytes
==================================================
downloaded 6040 bytes
* installing *source* package ‘askpass’ ...
** package ‘askpass’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
...
* DONE (askpass)
The downloaded source packages are in
    ‘/tmp/RtmpZX573M/downloaded_packages’

 


On RGui [RConsole]

Follow the below steps to configure RGui with Artifactory to resolve R packages:
1. We need an Identity Token which will be used to make authenticated requests to Artifactory. We can generate it manually or use Set Me Up option
2. Once we have the Identity Token, use the below sample configuration snippet and populate it with relevant/required values such as Artifactory-URL, repoName & Identity Token respectively:

local({
   r <- list(
     "<repoName>" = "https://<Artifactory-URL>/artifactory/<repoName>/"
   )
   options(repos = r)
 })
 options(download.file.method = "libcurl")
 options(download.file.extra = c("-v", "-L"))
 headers <- c("X-JFrog-Art-Api" = "<IdentityToken>")


3. After populating the sample configuration with the required values, copy it and paste it on the RGui console and hit Enter/Return to load it

User-added image 

4. Now, we can execute the below sample command with the required R library/package to download/install it:

install.packages("<package/libraryName>", method="libcurl", quiet = FALSE, extra = getOption("download.file.extra"), headers = headers)



Troubleshooting

  • Enabling De-bug logging for Cran in Artifactory

To enable de-bug logging for Cran in Artifactory, we need to add the below XML content to logback.xml file under $JFROG_HOME/artifactory/var/etc/artifactory directory. Enabling Cran de-bug can help us in identifying issues occurring on Artifactory (if any).
 

<!-- Cran de-bug logger -->
<appender name="cran" class="ch.qos.logback.core.rolling.RollingFileAppender">
  <File>${log.dir}/artifactory-cran.log</File>
  <rollingPolicy class="org.jfrog.common.logging.logback.rolling.FixedWindowWithDateRollingPolicy">
    <FileNamePattern>${log.dir.archived}/artifactory-cran.%i.log.gz</FileNamePattern>
    <maxIndex>10</maxIndex>
  </rollingPolicy>
  <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
    <MaxFileSize>25MB</MaxFileSize>
  </triggeringPolicy>
  <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
    <layout class="org.jfrog.common.logging.logback.layout.BackTracePatternLayout">
      <pattern>%date{yyyy-MM-dd'T'HH:mm:ss.SSS, UTC}Z [jfrt ] [%-5p] [%-16X{uber-trace-id}] [%-30.30(%c{3}:%L)] [%-20.20thread] - %m%n</pattern>
    </layout>
  </encoder>
</appender>

<logger name="org.artifactory.addon.cran" additivity="false">
<level value="debug"/>
<appender-ref ref="cran"/>
</logger>

<logger name="com.jfrog.ph.cran" additivity="false">
<level value="debug"/>
<appender-ref ref="cran"/>
</logger>

 

  • Check connectivity
  1. Ensure that Artifactory is able to access upstream URL directly or over a proxy
  2. Make sure that the client is able to communicate with Artifactory
  • Verify Certificates
  1. If Artifactory is configured with Self-signed TLS certificates, we will encounter SSL trust issues on the R client, therefore make sure to trust the Artifactory SSL certificates on R.
  2. If there is an SSL/TLS certificate issue with the upstream endpoint on Artifactory, then refer to our knowledge base article.

Sometimes, while installing R packages, we might encounter ‘package ‘<packageName>’ is not available for this version of R’. This indicates that the R version we are currently using is incompatible with the package we intend to install/use.

Related Links
CRAN repositories
Deploy CRAN packages