R(CRAN)
Create an R or CRAN registry, generate an identity token, then publish private R packages or cache public CRAN packages through an upstream proxy.
Use an R (CRAN) registry to host private R packages or cache public packages from CRAN-compatible repositories through an upstream proxy.
What you will learn from this topic
By the end of this quickstart guide, you will be able to:
Create a registry.
Publish a package to the registry.
Install the package from the registry, and confirm the working.
Before you begin
Install R on your local machine, including the standard package tools (
install.packages).Install
curlon your local machine. You use it to upload packages to your registry.Make sure you have access to a Harness account with permission to create registries and connectors.
Create a CRAN registry
To create a CRAN registry, perform the following steps:
In Artifact Registry, select Registries.
Click + Create Registry.
Specify the Registry name.
Optionally, add a Description.
Choose visibility between Public and Private. The default is Private.
Select CRAN as the Registry type.
Click Save.
Select Create to finalize.
Configure an upstream proxy (optional)
An upstream proxy allows your registry to fetch R packages from external CRAN-compatible repositories when they are not available locally. The default upstream is https://cran.r-project.org.
Create upstream proxy
To create an upstream proxy, perform the following steps:
In Artifact Registry, select Registries.
Click the drop-down next to + Create Registry and select Upstream Proxy.
Specify the Registry name.
Optionally, add a Description.
Choose visibility between Public and Private. The default is Private.
Select CRAN as the Registry type.
Select the Source: CRAN or Custom.
If you select Custom, specify the Remote registry URL (for example,
https://cran.r-project.org).
Select the Authentication method.
Username and password: Specify the username and password. Use an existing secret, or create a new secret by specifying the Name and entering the Secret text.
Anonymous: No credentials required. This works for public CRAN mirrors.
Select Create to finalize.
Configure the upstream proxy in your registry
To configure the upstream proxy in your registry, perform the following steps:
In Artifact Registry, select an existing R (CRAN) artifact.
Navigate to the Configuration tab.
Select Edit in the Upstream proxy section.
Click + Add upstream proxy.
Select the required proxy from the list.
Select Apply.
Click Update to finalize.
R (CRAN) client setup
In your Harness R (CRAN) Artifact, select the required CRAN registry, and then click Set Up Client. The dialog gives you an identity token, then setup instructions for configuring R, publishing packages, and installing packages.
Generate an identity token
An identity token serves as the password for authenticating with the registry.
In your Harness R (CRAN) Artifact, select Set Up Client.
Select Generate Token.
Select an Expiration for the token:
30 Days
90 Days
180 Days
Custom
Copy the token. You use it in the following steps in place of
<API_KEY>.
Configure the client
In the code samples, replace the values in angle brackets with your own values. Set Up Client fills in your account ID and registry name.
1. Configure R
Point R at this registry as a CRAN-like repository.
Store your identity token in a ~/.netrc file with mode 0600. Use your Harness account email as the login, and the identity token as the password:
Set the repository for the current R session. Downloads use the curl method with -n so curl reads credentials from ~/.netrc:
Persist across sessions by appending the same line to ~/.Rprofile:
2. Install a package
Install R packages from this registry:
3. Install an archived (older) version
The live index only lists the latest version of a package. Superseded source versions are still downloadable from the Archive/ path.
Install directly from the archived source tarball:
4. Upload a package
Upload an R source or binary archive to the registry using the CRAN repository layout.
Upload a source package to src/contrib (produced by R CMD build):
Upload a Windows binary to bin/windows/contrib/<R_MINOR_VERSION> (for example, 4.4):
Upload a macOS binary to bin/macosx/<FLAVOR>/contrib/<R_MINOR_VERSION> (for example, big-sur-arm64, 4.4):
Setup verification
Confirm that your registry serves the package you published.
In a new R session, use
install.packagesto install the package you published.Confirm that R downloaded the package from your Harness registry address, that is shown in Set Up Client.
In Harness, open your registry and confirm that the package and version appear in the package list.
If a step fails, go to Troubleshooting to resolve common authentication and resolution issues before you retry.
Pipeline automation (optional)
Publishing from a pipeline gives you a repeatable release process. Run the publish step when you create a version tag, so each release maps to one version in the registry.
The following Run step shows the shape of a publish step. Replace the placeholder values with your own. Store the identity token as a Harness secret, and do not write it into the pipeline YAML.
Troubleshooting
Next steps
To add a pipeline that publishes a new version for every release tag, go to Harness CI.
To control who can publish and consume packages in your registry, go to RBAC and permissions.
To set retention and lifecycle rules for old versions, go to Lifecycle Management overview.
Last updated
Was this helpful?