> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/artifact-registry/new-to-artifact-registry/quickstart/r-cran-quickstart.md). Agents can also search and read this documentation through its [MCP server](https://developer.harness.io/~gitbook/mcp).

# R (CRAN)

Get started with R (CRAN) packages in Harness Artifact Registry.

{% @harness-package-selector/package-selector platforms="%5B%7B%22label%22%3A%22Docker%22%2C%22slug%22%3A%22docker%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fdocker-quickstart%22%7D%2C%7B%22label%22%3A%22Helm%22%2C%22slug%22%3A%22helm%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fhelm-quickstart%22%7D%2C%7B%22label%22%3A%22Helm%20HTTP%22%2C%22slug%22%3A%22helm-http%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fhelm-http-quickstart%22%7D%2C%7B%22label%22%3A%22Generic%22%2C%22slug%22%3A%22generic%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fgeneric-quickstart%22%7D%2C%7B%22label%22%3A%22Raw%20File%22%2C%22slug%22%3A%22raw-file%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fraw-file-quickstart%22%7D%2C%7B%22label%22%3A%22Maven%22%2C%22slug%22%3A%22maven%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fmaven-quickstart%22%7D%2C%7B%22label%22%3A%22Python%22%2C%22slug%22%3A%22python%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fpython-quickstart%22%7D%2C%7B%22label%22%3A%22NPM%22%2C%22slug%22%3A%22npm%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fnpm-quickstart%22%7D%2C%7B%22label%22%3A%22Nuget%22%2C%22slug%22%3A%22nuget%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fnuget-quickstart%22%7D%2C%7B%22label%22%3A%22RPM%22%2C%22slug%22%3A%22rpm%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Frpm-quickstart%22%7D%2C%7B%22label%22%3A%22Debian%22%2C%22slug%22%3A%22debian%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fdebian-quickstart%22%7D%2C%7B%22label%22%3A%22Alpine%22%2C%22slug%22%3A%22alpine%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Falpine-quickstart%22%7D%2C%7B%22label%22%3A%22Wolfi%22%2C%22slug%22%3A%22wolfi%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fwolfi-quickstart%22%7D%2C%7B%22label%22%3A%22Cargo%22%2C%22slug%22%3A%22cargo%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fcargo-quickstart%22%7D%2C%7B%22label%22%3A%22Conan%22%2C%22slug%22%3A%22conan%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fconan-quickstart%22%7D%2C%7B%22label%22%3A%22Go%22%2C%22slug%22%3A%22go%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fgo-quickstart%22%7D%2C%7B%22label%22%3A%22Hugging%20Face%22%2C%22slug%22%3A%22hugging-face%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fhugging-face-quickstart%22%7D%2C%7B%22label%22%3A%22Conda%22%2C%22slug%22%3A%22conda%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fconda-quickstart%22%7D%2C%7B%22label%22%3A%22Dart%22%2C%22slug%22%3A%22dart%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fdart-quickstart%22%7D%2C%7B%22label%22%3A%22PHP%20Composer%22%2C%22slug%22%3A%22php-composer%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fphp-composer-quickstart%22%7D%2C%7B%22label%22%3A%22Swift%22%2C%22slug%22%3A%22swift%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fswift-quickstart%22%7D%2C%7B%22label%22%3A%22Puppet%22%2C%22slug%22%3A%22puppet%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fpuppet-quickstart%22%7D%2C%7B%22label%22%3A%22Terraform%22%2C%22slug%22%3A%22terraform%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fterraform-quickstart%22%7D%2C%7B%22label%22%3A%22R%20(CRAN)%22%2C%22slug%22%3A%22r-cran%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Fr-cran-quickstart%22%7D%2C%7B%22label%22%3A%22RubyGems%22%2C%22slug%22%3A%22rubygems%22%2C%22path%22%3A%22artifact-registry%2Fnew-to-artifact-registry%2Fquickstart%2Frubygems-quickstart%22%7D%5D" selectedPlatform="r-cran" %}

The R registry supports the Comprehensive R Archive Network (CRAN) package format. You can host private R packages or cache public packages through an upstream proxy. Configure your R client to install packages from the registry, or to publish packages to it.

***

## Before you begin <a href="#before-you-begin" id="before-you-begin"></a>

Complete these prerequisites before you create a CRAN registry:

* **R:** Installed on your local machine, including the standard package tools (`install.packages`).
* **Harness account:** Access with permissions to create registries and connectors.

***

### Create a CRAN Artifact Registry <a href="#create-a-cran-artifact-registry" id="create-a-cran-artifact-registry"></a>

{% tabs %}
{% tab title="Interactive Guide" %}
{% embed url="<https://app.arcade.software/share/hgAQwSj24wEqZLrRk6sj>" %}
Create a CRAN Artifact Registry in Harness
{% endembed %}
{% endtab %}

{% tab title="Step-by-Step" %}
To create a CRAN Artifact Registry, perform the following steps:

1. Navigate to the Artifact Registry module in your Harness project.
2. Click **New Artifact Registry**.
3. In the Registry Type list, select **CRAN**.
4. Enter a **Registry Name**.

{% hint style="info" %}
**REGISTRY NAME CRITERIA**

The registry name must start with a letter, should only contain lowercase alphanumerics, `_`, `.` and `-`, and *must be unique to your Harness account*.
{% endhint %}

5. Optionally, add a **Description** and **Labels** for better organization.
6. Select visibility between **Public** and **Private**. *By default, the visibility is set to Private*.
7. Click **Create Registry** to finalize.
   {% endtab %}
   {% endtabs %}

***

### Configure an upstream proxy (optional) <a href="#configure-an-upstream-proxy-optional" id="configure-an-upstream-proxy-optional"></a>

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

{% tabs %}
{% tab title="Interactive Guides" %}
**Create an upstream proxy**

{% embed url="<https://app.arcade.software/share/YuIyLlF9NG9PuKIuFFTc>" %}
Create a CRAN Upstream Proxy in Harness
{% endembed %}

**Configure the upstream proxy in your registry**

{% embed url="<https://app.arcade.software/share/UyHbXnIRN9Okjgw8shBT>" %}
Configure CRAN Upstream Proxy in Harness
{% endembed %}
{% endtab %}

{% tab title="Step-by-Step" %}

#### Create an upstream proxy <a href="#create-an-upstream-proxy" id="create-an-upstream-proxy"></a>

To create an upstream proxy, perform the following steps:

1. In the Artifact Registry module, open the dropdown next to **New Artifact Registry**, then select **Upstream Proxy**.
2. Select **CRAN** as the proxy type.
3. Enter an **Upstream Proxy Key**.
4. Optionally, add a **Description** and **Labels**.
5. Select your **Source**:
   * CRAN
   * Custom
6. If you select Custom, enter your **Remote Registry URL** (for example, `https://cran.r-project.org`).
7. Select your **Authentication** method (`Anonymous` by default for public CRAN mirrors).
8. Click **Create Upstream Proxy** to establish the connection.

#### Configure the upstream proxy in your registry <a href="#configure-the-upstream-proxy-in-your-registry" id="configure-the-upstream-proxy-in-your-registry"></a>

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

1. In the Artifact Registry module, select an existing R (CRAN) Artifact Registry.
2. Select the **Configuration** tab.
3. In the **Advanced (Optional)** section, click **Configure Upstream**.
4. Select from the list of compatible proxies to add them to your registry.
5. Click **Save** to save the configuration.
   {% endtab %}
   {% endtabs %}

{% hint style="info" %}
**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.
{% endhint %}

***

### Set up the CRAN package client <a href="#set-up-the-cran-package-client" id="set-up-the-cran-package-client"></a>

In your Harness CRAN Artifact Registry, click **Set Up Client** and follow the instructions to install or use R packages from the registry.

1. Generate an identity token:

   i. In your Harness CRAN Artifact Registry, click **Set Up Client**.

   ii. Click **Generate Token** to generate an identity token.
2. Configure R:

   Point R at this registry as a CRAN-like repository.

   i. Set the repository for the current R session:

   ```r
   options(
     repos = c(
     HARNESS = "https://pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/cran"
     ))
   ```

   ii. Persist across sessions by appending the same line to \~/.Rprofile:

   ```bash
   echo 'options(repos = c(HARNESS = "https://pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/cran"))' >> ~/.Rprofile

   ```

   iii. Route downloads through libcurl and attach the identity token:

   ```r
   options(download.file.method = "libcurl", download.file.extra = "-H 'x-api-key: <API_KEY>'")

   ```
3. Install a package:

   ```r
   install.packages("<ARTIFACT_NAME>")

   ```
4. 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 a specific version using the `remotes` package:

   ```r
   remotes::install_version("<ARTIFACT_NAME>", version = "<VERSION>", repos = "https://pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/cran")
   ```

   OR

   install directly from the archived source tarball:

   ```r
   install.packages("https://pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/cran/src/contrib/Archive/<ARTIFACT_NAME>/<ARTIFACT_NAME>_<VERSION>.tar.gz", repos = NULL, type = "source")

   ```
5. Upload a package:

   Upload an R source or binary archive to the registry using the CRAN repository layout.

   i. Upload a source package to `src/contrib` (produced by `R CMD build`):

   ```bash

   curl --location --request PUT 'https://pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/files/src/contrib/<FILE_NAME>' \
   --header 'x-api-key: <API_KEY>' \
   --upload-file '<FILE_PATH>'

   ```

   ii. Upload a Windows binary to `bin/windows/contrib/<R_MINOR_VERSION>` (for example, `4.4`):

   ```bash

   curl --location --request PUT 'https://pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/files/bin/windows/contrib/<R_MINOR_VERSION>/<FILE_NAME>' \
   --header 'x-api-key: <API_KEY>' \
   --upload-file '<FILE_PATH>'

   ```

   iii. Upload a macOS binary to `bin/macosx/<FLAVOR>/contrib/<R_MINOR_VERSION>` (for example, `big-sur-arm64`, `4.4`):

   ```bash

   curl --location --request PUT 'https://pkg.harness.io/pkg/<ACCOUNT_ID>/<REGISTRY_NAME>/files/bin/macosx/<FLAVOR>/contrib/<R_MINOR_VERSION>/<FILE_NAME>' \
   --header 'x-api-key: <API_KEY>' \
   --upload-file '<FILE_PATH>'

   ```

***

## Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

Select any issue below to expand it and view the cause and fix.

<details>

<summary><code>install.packages</code> fails with <code>401</code> or <code>403</code> against an R (CRAN) registry</summary>

Confirm the identity token from **Set Up Client** is set in `download.file.extra` as `-H 'x-api-key: <API_KEY>'`, and that `download.file.method` is `libcurl`. Regenerate the token if it expired, and verify your principal has Artifact Registry permissions on the registry.

If header-based auth still fails, configure `~/.netrc` with the registry host, set the login and password to the identity token, run `chmod 600 ~/.netrc`, and switch `download.file.method` to `curl` with extra flags `-n -L -f`.

</details>

<details>

<summary>Set Up Client does not show Upload a package</summary>

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.

</details>

<details>

<summary>Publish to a CRAN registry returns <code>409 Conflict</code></summary>

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.

</details>

<details>

<summary><code>install.packages</code> returns <code>404 Not Found</code> or cannot find an older package version</summary>

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.

</details>

***

## Next steps <a href="#next-steps" id="next-steps"></a>

You have a CRAN registry you can use to install and publish R packages. Continue with these topics:

* Go to [Configure an upstream proxy](https://developer.harness.io/artifact-registry/use-artifact-registry/manage-registries/upstream-proxy.md) to cache packages from remote CRAN sources.
* Go to [Configure a registry](https://developer.harness.io/artifact-registry/use-artifact-registry/manage-registries/configure-registry.md) to manage registry settings.
* Go to [Artifact management](https://developer.harness.io/artifact-registry/use-artifact-registry/manage-artifacts/artifact-management.md) to find, download, and manage packages.

{% @harness-feedback/feedback %}
