R Buildpack

Page last updated:

This topic describes how to push your R app to Cloud Foundry and how to configure your R app to use the R buildpack.

Push an App

Cloud Foundry automatically uses the R buildpack if it detects a r.yml file in the root directory of your project.

If your Cloud Foundry deployment does not have the R buildpack installed, or the installed version is out of date, you can use the latest version by specifying it with the -b option when you push your app. For example:

$ cf push my_app -b https://github.com/cloudfoundry/r-buildpack.git

Supported Versions

You can find the list of supported R versions in the R buildpack release notes.

Start Command

The R buildpack does not generate a default start command for your applications. Instead, you must specify a start command for your app.

To stage an app with the R buildpack and start the app, do one of the following:

  • Option 1: Supply a Procfile. For more information about Procfiles, see Production Server Configuration. The following example Procfile specifies R -f as the start command for a web app with the entrypoint simple.r:

    web: R -f simple.r
    
  • Option 2: Specify a start command with -c:

    $ cf push r-app -c "R -f simple.r"
    
  • Option 3: Specify a start command in the application manifest by setting the command attribute. For more information, see the Deploying with Application Manifests topic.

For more information about starting apps, see Starting, Restarting, and Restaging Applications.

Specifying App Dependencies

As of v0.0.5, the following packages are provided by the buildpack:

  • Rserve
  • forecast
  • shiny

To specify additional packages needed by your app, provide the CRAN mirror and names of the packages inside your r.yml file. For example:

---
packages:
  - cran_mirror: https://cran.r-project.org
    packages:
      - name: stringr
      - name: jsonlite

Vendoring App Dependencies

If you are deploying in an environment that is disconnected from the Internet, you must vendor your app’s dependencies, which means you must make these packages available for offline use. You can vendor dependencies by using a package manager.

To set up your own custom, local CRAN-like repository to vendor your packages, create the src/contrib directories and populate them with your package source tarballs. For more information, see How to Set Up a Custom CRAN-like Repository published on the Packrat Documentation site.

Add the src/contrib directories containing your package tarballs to a vendor_r directory at the root of your app. This directory is named vendor_r so as not to conflict with vendor directories of other languages, such as python.

Then, inside your r.yml, provide the names of your vendored packages in the packages list:

---
packages:
  - packages:
      - name: stringr
      - name: jsonlite

cf push uploads your vendored dependencies. The buildpack installs them directly from the vendor_r/ directory.

Example app directory tree:

├── r.yml
├── simple-app.r
└── vendor_r
    └── src
        └── contrib
            ├── PACKAGES
            ├── PACKAGES.gz
            ├── jsonlite_1.5.tar.gz
            └── stringr_1.3.1.tar.gz

For more information about using buildpacks in disconnected environments, see Disconnected environments.

Proxy Support

If you need to use a proxy to download dependencies during staging, you can set the http_proxy and https_proxy environment variables. For more information, see the Proxy Usage Documentation.

BOSH Configured Custom Trusted Certificate Support

R uses certificates stored in /etc/ssl/certs. Your platform operator can configure the platform to add the custom certificates into the application container. For more information, see Configuring Trusted Sytsem Certificates for Applications.

Help and Support

Join the #buildpacks channel in our Slack community if you need any further assistance.

For more information about using and extending the R buildpack in Cloud Foundry, see the R-buildpack GitHub repository.

You can also find current information about this buildpack on the R buildpack release page in GitHub.

Create a pull request or raise an issue on the source for this page in GitHub