CRAN Repository

Cloudsmith provides public & private repositories for R packages

R is a free software environment for statistical computing and graphics. CRAN or Comprehensive R Archive Network is the repository for R packages.

For more information on R, please see:

  • R: The official website for R
  • CRAN: The official list of mirrors public repositories
  • CRAN Package Repository: The official package repository
Contextual Documentation

The examples in this document are generic. Cloudsmith provides contextual setup instructions within each repository, complete with copy n' paste snippets (with your namespace/repo/rsa-key pre-configured).

In the following examples:

IdentifierDescription
OWNERYour Cloudsmith account name or organization name (namespace)
REPOSITORYYour Cloudsmith Repository name (also called "slug")
TOKENYour Cloudsmith Entitlement Token (see Entitlements for more details)
USERNAMEYour Cloudsmith username
PASSWORDYour Cloudsmith password
API-KEYYour Cloudsmith API Key
PACKAGE_NAMEThe name of your package
PACKAGE_VERSIONThe version number of your package

Upload a Package

To upload, you will need to generate a package first. Hadley Wickham's R Packages book provides the best overview of what is required to do so. We highly recommend following the best practices outlined in the book (it's available free online).

Cloudsmith CRAN repositories support uploading both source and binary packages. The package type is determined via the package file extension:

  • .tar.gz for source packages.
  • .zipfor Windows binary packages.
  • .tgzfor macOS binary packages.

CRAN binaries are built for a specific R version, and if it's a macOS binary, an architecture too. These can be easily specified when uploading via the UI, API, or CLI.

Upload via the Cloudsmith CLI

For full details of how to install and setup the Cloudsmith CLI, see Command Line Interface.

The command to upload a R/CRAN package via the Cloudsmith CLI is:

cloudsmith push cran OWNER/REPOSITORY PACKAGE_NAME_PACKAGE_VERSION.tar.gz

For a source package:

cloudsmith push cran org/repo your-package_0.1.0.tar.gz

For a Windows binary package:

cloudsmith push cran org/repo your-package_0.1.0.zip --r-version 4.3

For a macOS binary package:

cloudsmith push cran org/repo your-package_0.1.0.tgz --r-version 4.3 --architecture arm64

Upload via Cloudsmith Website

Please see Upload a Package for details of how to upload via the Website UI.

Upload via API

Please see Create a new CRAN package for details of how to upload via the API.


Download / Install a Package

To install a package, use the install.packages method directly in your R session. Including type = "binary" within the method will instruct CRAN to install the binary. With this, R will not check that a source package is available and of a higher version. For binary installations, the type must be set if no matching source package exists within your repository:

Public Repositories

install.packages(
  "PACKAGE_NAME",
  repos = c(cloudsmith = "https://dl.cloudsmith.io/public/OWNER/REPOSITORY/cran/")
)

Private Repositories

📘

Private Cloudsmith repositories require authentication. You can choose between two types of authentication, Entitlement Token Authentication or HTTP Basic Authentication.

The setup method will differ depending on what authentication type you choose to use.

🚧

Entitlement Tokens, User Credentials and API-Keys should be treated as secrets, and you should ensure that you do not commit them in configurations files along with source code or expose them in any logs

install.packages(
  "PACKAGE_NAME",
  repos = c(cloudsmith = "https://dl.cloudsmith.io/TOKEN/OWNER/REPOSITORY/cran/")
)
install.packages(
  "PACKAGE_NAME",
  repos = c(cloudsmith = "https://USERNAME:[email protected]/basic/OWNER/REPOSITORY/cran/")
)
install.packages(
  "PACKAGE-NAME",
  repos = c(cloudsmith = "https://USERNAME:[email protected]/basic/OWNER/REPOSITORY/cran/")
)
install.packages(
  "PACKAGE-NAME",
  repos = c(cloudsmith = "https://token:[email protected]/basic/OWNER/REPOSITORY/cran/")
)

For most use cases, users will probably want to persist their repository settings and not specify them every time. To set the repository and avoid having to specify this during every package installation, create the R startup command file .Rprofile in your home directory and add the following R code to it:

Public Repositories

print("Configuring CRAN repositories")
r = getOption("repos")
r["cloudsmith"] = "https://dl.cloudsmith.io/public/OWNER/REPOSITORY/cran/"
r["CRAN"] = "https://cloud.r-project.org"
options(repos = r)
rm(r)

Private Repositories

print("Configuring CRAN repositories")
r = getOption("repos")
r["cloudsmith"] = "https://dl.cloudsmith.io/TOKEN/OWNER/REPOSITORY/cran/"
r["CRAN"] = "https://cloud.r-project.org"
options(repos = r)
rm(r)
print("Configuring CRAN repositories")
r = getOption("repos")
r["cloudsmith"] = "https://USERNAME:[email protected]/basic/OWNER/REPOSITORY/cran/"
r["CRAN"] = "https://cloud.r-project.org"
options(repos = r)
rm(r)
print("Configuring CRAN repositories")
r = getOption("repos")
r["cloudsmith"] = "https://USERNAME:[email protected]/basic/OWNER/REPOSITORY/cran/"
r["CRAN"] = "https://cloud.r-project.org"
options(repos = r)
rm(r)
print("Configuring CRAN repositories")
r = getOption("repos")
r["cloudsmith"] = "https://token:[email protected]/basic/OWNER/REPOSITORY/cran/"
r["CRAN"] = "https://cloud.r-project.org"
options(repos = r)
rm(r)

Upstream Proxying / Caching

Configurable Proxying Caching
You can configure upstream CRAN repositories that you wish to use for R packages that are not available in your Cloudsmith repository. In addition, you can also choose to cache any requested packages for future use.

Please see our Upstream Proxying documentation for further instructions.

Troubleshooting

Please see the Troubleshooting page for further help and information.


Cloudsmith is the new standard in Package / Artifact Management and Software Distribution

With support for all major package formats, you can trust us to manage your software supply chain.


Start My Free Trial Now
Cookie Declaration (Manage Cookies)