Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.
ArtifactsRegistry TypesGetting Started

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 curl on 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:

  1. In Artifact Registry, select Registries.

  2. Click + Create Registry.

  3. Specify the Registry name.

Registry name criteria

The registry name must start with a letter, can only contain lowercase alphanumerics, _, ., and -, and must be unique to your Harness account.

  1. Optionally, add a Description.

  2. Choose visibility between Public and Private. The default is Private.

  3. Select CRAN as the Registry type.

  4. Click Save.

  5. 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:

  1. In Artifact Registry, select Registries.

  2. Click the drop-down next to + Create Registry and select Upstream Proxy.

  3. Specify the Registry name.

  4. Optionally, add a Description.

  5. Choose visibility between Public and Private. The default is Private.

  6. Select CRAN as the Registry type.

  7. Select the Source: CRAN or Custom.

    • If you select Custom, specify the Remote registry URL (for example, https://cran.r-project.org).

  8. 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.

  9. Select Create to finalize.

Configure the upstream proxy in your registry

To configure the upstream proxy in your registry, perform the following steps:

  1. In Artifact Registry, select an existing R (CRAN) artifact.

  2. Navigate to the Configuration tab.

  3. Select Edit in the Upstream proxy section.

  4. Click + Add upstream proxy.

  5. Select the required proxy from the list.

  6. Select Apply.

  7. Click Update to finalize.

Upstream proxy caching

If a package is not found in your Harness registry, the upstream proxy fetches it from the remote CRAN-compatible repository and caches it.

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.

  1. In your Harness R (CRAN) Artifact, select Set Up Client.

  2. Select Generate Token.

  3. Select an Expiration for the token:

    • 30 Days

    • 90 Days

    • 180 Days

    • Custom

  4. Copy the token. You use it in the following steps in place of <API_KEY>.

Token expiration

The identity token stops working after the expiration you select. Generate a new token and update your client configuration before the current token expires.

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.

  1. In a new R session, use install.packages to install the package you published.

  2. Confirm that R downloaded the package from your Harness registry address, that is shown in Set Up Client.

  3. 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

`install.packages` fails with `401` or `403` against an R (CRAN) registry

Confirm ~/.netrc lists machine pkg.harness.io, your Harness account email as login, and the identity token from Set Up Client as password. The file must be mode 0600 (chmod 600 ~/.netrc). Confirm download.file.method is curl and download.file.extra is -n -L -f so curl reads that file. Regenerate the token if it expired, update ~/.netrc, and verify your principal has Artifact Registry permissions on the registry.

For uploads, confirm the curl PUT includes --header 'x-api-key: <API_KEY>' with the same identity token.

Set Up Client does not show Upload a package

Upload is available only on a virtual CRAN registry. An upstream CRAN registry is pull-only, so Set Up Client omits Upload a package. Publish to a virtual registry instead, or cache packages through the upstream proxy.

Publish to a CRAN registry returns `409 Conflict`

Package versions are immutable after publish. Use a new package version, or delete the existing version only if your registry retention and lifecycle policies allow it. Do not PUT to an upstream registry.

`install.packages` returns `404 Not Found` or cannot find an older package version

Confirm the registry URL includes your account ID and registry name. The live index lists only the latest version, so install older versions from the src/contrib/Archive tarball URL. If you rely on an upstream proxy, confirm the proxy is attached and the remote CRAN URL is reachable.

Next steps

Last updated

Was this helpful?