{"id":17998382,"url":"https://github.com/primaryobjects/heroku-buildpack-r-20","last_synced_at":"2025-10-06T21:20:56.609Z","repository":{"id":139343241,"uuid":"438770943","full_name":"primaryobjects/heroku-buildpack-r-20","owner":"primaryobjects","description":"Heroku R Buildback for heroku-18 and heroku-20 stacks.","archived":false,"fork":false,"pushed_at":"2021-12-18T15:37:25.000Z","size":7856,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-09T17:47:49.352Z","etag":null,"topics":["buildback","heroku","heroku-18","heroku-20","heroku-buildpack","heroku-deployment","r"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/primaryobjects.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-15T20:57:19.000Z","updated_at":"2021-12-18T15:37:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"bd987d60-02b7-4f93-961c-f303755c4504","html_url":"https://github.com/primaryobjects/heroku-buildpack-r-20","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/primaryobjects%2Fheroku-buildpack-r-20","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/primaryobjects%2Fheroku-buildpack-r-20/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/primaryobjects%2Fheroku-buildpack-r-20/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/primaryobjects%2Fheroku-buildpack-r-20/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/primaryobjects","download_url":"https://codeload.github.com/primaryobjects/heroku-buildpack-r-20/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247135123,"owners_count":20889420,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["buildback","heroku","heroku-18","heroku-20","heroku-buildpack","heroku-deployment","r"],"created_at":"2024-10-29T21:25:00.941Z","updated_at":"2025-10-06T21:20:51.557Z","avatar_url":"https://github.com/primaryobjects.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Heroku Buildpack: R\n\nThis is a [Heroku Buildpack][buildpacks] for applications which use [R][rproject] for statistical computing and [CRAN][cran] for R packages.\n\nThe buildpack supports the [heroku-18][stack18] and [heroku-20][stack20] stacks.\n\nIt also includes support for the [Packrat][packrat] and [renv][renv] package managers, and the [Shiny][shiny] and [Plumber][plumber] web application frameworks.\n\n## Usage\n\nThe buildpack URL is [`https://github.com/virtualstaticvoid/heroku-buildpack-r.git`][bpurl]. Provide it when creating your application on Heroku as follows:\n\n```\nheroku create --buildpack https://github.com/virtualstaticvoid/heroku-buildpack-r.git\n```\n\nThe buildpack will detect your application makes use of R if it has one (or more) of the following files in the project directory:\n\n* `init.R`\n* `packrat/init/R`\n* `renv/activate.R`\n* `run.R`\n* `app.R`\n* `plumber.R`\n\nIf the `init.R` file is provided, it will be executed in order to install any R packages, and if `packrat/init.R` or `renv/activate.R` files are found, the respective package manager will be bootstrapped and packages installed.\n\nAdditionally:\n\n* If the `run.R` file is provided, the buildpack will be configured as a Shiny application.\n* If the `plumber.R` file is provided, the buildpack will be configured as a Plumber application.\n\nSee the [detect](bin/detect) script for the matching logic used.\n\n## Installing R Packages\n\nThe `init.R` file is used to install R packages as required.\n\n*NOTE:* Using either [Packrat][packrat] or [renv][renv] are a better way to manage your package dependencies and their respective versions, so the `init.R` file isn't required if you use `packrat` or `renv`.\n\nThe following example `init.R` file can be used. Provide the package names you want to install to the `my_packages` list variable:\n\n```\n# init.R\n#\n# Example R code to install packages if not already installed\n#\n\nmy_packages = c(\"package_name_1\", \"package_name_2\", ...)\n\ninstall_if_missing = function(p) {\n  if (p %in% rownames(installed.packages()) == FALSE) {\n    install.packages(p)\n  }\n}\n\ninvisible(sapply(my_packages, install_if_missing))\n```\n\nR packages can also be installed by providing a `.tar.gz` package archive file, if a specific version is required, or\nit is not a publicly published package. See [local-packages](test/local-packages) for an example.\n\n```\n# init.R\n#\n# Example R program to installed package from local path\n#\n\ninstall.packages(\"PackageName-Version.tar.gz\", repos=NULL, type=\"source\")\n```\n\n*NOTE:* The path to the package archive should be a relative path to the project root directory, so that it works locally in development and during deployment on Heroku.\n\n### R Package Installation Helper\n\nFor convenience, a R helper function, [`helpers.installPackages`](bin/helpers.R), is included by the buildpack to make installing packages easier.\n\nThus the `init.R` file can be reduced to a single line of R code as shown. Provide the package names you want to install as arguments to the helper:\n\n```\nhelpers.installPackages(\"package_name_1\", \"package_name_2\", ...)\n```\n\n## Installing Binary Dependencies\n\nThis version of the buildpack still supports the use of an `Aptfile` for installing additional system packages, however this functionality is going to be _deprecated_ in future as it isn't a foolproof solution.\n\nIt is based on the same technique as used by the [heroku-buildpack-apt][bpapt] buildpack to install Ubuntu packages using `apt-get`.\n\nThere are various technical and security reasons why it is no longer recommended, so your mileage may vary.\n\nIf any of your R packages dependend on system libraries which aren't [included by Heroku][herokupkgs], such as `libgmp`, `libgomp`, `libgdal`, `libgeos` and `libgsl`, you should use the Heroku [container stack][container-stack] together with [heroku-docker-r][heroku-docker-r] instead.\n\n### Manual Binary Dependencies\n\nTo maually download, build, and install binary dependencies (Linunx apt-get libraries, etc.) you can modify [compile](https://github.com/primaryobjects/heroku-buildpack-r-20/blob/master/bin/compile#L74-L85) and provide the url to download the file for building.\n\nCopy the example script in the \"compile\" file to add any additional libraries to your Heroku enviornment.\n\n**Example**\n\n```bash\necho \"-----\u003e Starting fftw compilation\"\necho \"Downloading http://www.fftw.org/fftw-3.3.10.tar.gz\" | indent\nwget --quiet http://www.fftw.org/fftw-3.3.10.tar.gz\necho \"Unpacking fftw\" | indent\ntar -xf fftw-3.3.10.tar.gz\ncd fftw-3.3.10\necho \"Running configure\" | indent\n./configure --prefix=\"$BUILD_DIR\" \u003e/dev/null 2\u003e\u00261\necho \"Running make with target install\" | indent\nmake install \u003e/dev/null 2\u003e\u00261\necho \"Running make with target distclean\" | indent\nmake distclean \u003e /dev/null 2\u003e\u00261\n```\n\n## R Applications\n\n### Heroku Console\n\nYou can run the R console application as follows:\n\n```\n$ heroku run R ...\n```\n\nType `q()` to exit the console when you are finished.\n\nYou can also run the `Rscript` utility as follows:\n\n```\n$ heroku run Rscript ...\n```\n\n_Note that the Heroku slug is read-only, so any changes you make during the session will be lost._\n\n### Shiny Applications\n\nShiny applications must provide a `run.R` file, and can also include an `init.R` in order to install additional R packages.\nThe Shiny package does not need to be installed, as it is included in the buildpack already.\n\nThe `run.R` file should contain at least the following code, in order to run the web application.\n\nNotice the use of the `PORT` environment variable, provided by Heroku, which is used to configure Shiny and the host must be `0.0.0.0`.\n\n```\n# run.R\nlibrary(shiny)\n\nport \u003c- Sys.getenv('PORT')\n\nshiny::runApp(\n  appDir = getwd(),\n  host = '0.0.0.0',\n  port = as.numeric(port)\n)\n```\n\nSee the [virtualstaticvoid/heroku-shiny-app][shiny-app] example application.\n\n### Plumber Applications\n\nPlumber applications must provide an `app.R` file, but can also include an `init.R` in order to install additional R packages.\nThe Plumber package does not need to be installed, as it is included in the buildpack already.\n\nThe `app.R` file should contain at least the following code, in order to run the web application.\n\nNotice the use of the `PORT` environment variable, provided by Heroku, which is used to configure Shiny and the host must be `0.0.0.0`.\n\n```\n# app.R\nlibrary(plumber)\n\nport \u003c- Sys.getenv('PORT')\n\nserver \u003c- plumb(\"plumber.R\")\n\nserver$run(\n  host = '0.0.0.0',\n  port = as.numeric(port)\n)\n```\n\nSee the [virtualstaticvoid/heroku-plumber-app][plumber-app] example application.\n\n### Recurring Jobs\n\nYou can use the [Heroku scheduler][scheduler] to schedule a recurring R process.\n\nAn example command for the scheduler to run `prog.R`, would be `R --file=prog.R --gui-none --no-save`.\n\n## Technical Details\n\n### R Versions\n\nThe buildpack currently supports `R 4.0.0`. This is updated periodically when new versions of R are released.\n\n### Slug Compilation vs Runtime use of `chroot`\n\nThis version of the buildpack still uses a [fakechroot][fakechroot] during slug compilation, to compile R packages which may include C or Fortran code.\nHowever it no longer uses the `chroot` at runtime so it can work better in scenarios where other language buildpacks are used, such as with Python, Ruby or Java, and so that the [slug size][slugsize] is greatly reduced.\n\nIf you are migrating to this version of the buildpack, you no longer need to prefix commands to use `fakechroot`, `fakeroot` or `chroot`.\nWrappers of these commands are included and they will output warning messages to alert you of their use.\n\n### Buildpack Binaries\n\nThe binaries used by the buildpack are hosted on AWS S3 at [https://heroku-buildpack-r.s3.amazonaws.com][s3].\n\nSee the [heroku-buildpack-r-build2][build2] repository for building the buildpack binaries yourself.\n\n### Process Types\n\nThe buildpack includes the following default process types:\n\n* `console`: Executes the `R` terminal application, which is typically used for debugging.\n* `web`: Executes `run.R` to run Shiny or Plumber applications.\n\nThe `R` and `Rscript` executables are available like any other executable, via the `heroku run` command.\n\n#### Procfile\n\nYou can include a [Procfile][procfile] in your project if you want to override the default process types and/or their command lines. This is typically required if you are using multiple buildpacks.\n\nFor example, the following Profile defines the commands for the `web` and `console` processes.\n\n```\nweb: R --file=myprogram.R --gui-none --no-save\nconsole: R --no-save\n```\n\n#### `heroku.yml`\n\nYou can include the [`heroku.yml`][herokuyml] build manifest in you project if you want to override the default process types and/or their command lines, within the `run` section. This is typically required if you are using multiple buildpacks.\n\nFor example, the following `heroku.yml` file defines the commands for the `web` and `console` processes.\n\n```\nrun:\n  web: R --file=myprogram.R --gui-none --no-save\n  console: R --no-save\n```\n\n### Paths\n\nWhere possible, always use relative paths for files, so that your application is more portable; so that it can run locally in development and at runtime on Heroku without any differences.\n\nThe current directory on Heroku will always be `/app` and your application will be installed to this directory, so relative paths should be in respect of the root directory of your project.\n\nIf you need to use absolute paths, consider using [`getwd()`][getwd] together with [`file.path()`][filepath] to build up the path instead of hardcoding them.\n\n### `.Rprofile`\n\nYou can include an [`.Rprofile`][rprofile] in your application's root directory and it will be executed at the start of any R process.\n\nIt can be used as a convenient way to bootstrap your application, sourcing common utilities or performing configuration tasks.\n\nPlease _do not_ use it to install R packages, since it may cause problems during deployment (slug compilation) and  _will_ fail at runtime.\n\n### CRAN Mirror Override\n\nIt is possible to override the default CRAN mirror used, by providing the URL via the `CRAN_MIRROR` environment variable.\n\nE.g. Override the URL by setting the variable as follows.\n\n```\nheroku config:set CRAN_MIRROR=https://cloud.r-project.org/\n```\n\nCheck the CRAN [mirror status][mirrors] page to ensure the mirror is available.\n\n### Caching\n\nTo improve the time it takes to deploy the buildpack caches the R binaries and installed R packages.\n\nIf you need to purge the cache, it is possible by using [heroku-repo][heroku-repo] CLI plugin via the `heroku repo:purge_cache` command.\n\nSee the [purge-cache][purge] documentation for more information.\n\n## Credits\n\n* Original inspiration from [Noah Lorang's Rook on Heroku][rookonheroku] project.\n* Script snippets from the [rstudio/r-builds][r-builds] project.\n* Tests from the [rstudio/r-docker][r-docker] project.\n* [fakechroot][fakechroot] library.\n* [tcl/tk][tcltk] library.\n\n## License\n\nMIT License. Copyright (c) 2020 Chris Stefano. See [LICENSE](LICENSE) for details.\n\n[bpapt]: https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-apt\n[bpurl]: https://github.com/virtualstaticvoid/heroku-buildpack-r.git\n[build2]: https://github.com/virtualstaticvoid/heroku-buildpack-r-build2\n[buildpacks]: https://devcenter.heroku.com/articles/buildpacks\n[container-stack]: https://devcenter.heroku.com/categories/deploying-with-docker\n[cran]: https://cran.r-project.org\n[fakechroot]: https://github.com/dex4er/fakechroot/wiki\n[filepath]: https://www.rdocumentation.org/packages/base/versions/3.6.0/topics/file.path\n[getwd]: https://www.rdocumentation.org/packages/base/versions/3.6.0/topics/getwd\n[heroku-docker-r]: https://github.com/virtualstaticvoid/heroku-docker-r\n[heroku-repo]: https://github.com/heroku/heroku-repo\n[herokupkgs]: https://devcenter.heroku.com/articles/stack-packages\n[herokuyml]: https://devcenter.heroku.com/articles/build-docker-images-heroku-yml#run-defining-the-processes-to-run\n[mirrors]: https://cran.r-project.org/mirmon_report.html\n[packrat]: http://rstudio.github.io/packrat\n[plumber-app]: https://github.com/virtualstaticvoid/heroku-plumber-app\n[plumber]: https://www.rplumber.io\n[procfile]: https://devcenter.heroku.com/articles/procfile\n[purge]: https://github.com/heroku/heroku-repo#purge-cache\n[r-builds]: https://github.com/rstudio/r-builds\n[r-docker]: https://github.com/rstudio/r-docker\n[renv]: https://rstudio.github.io/renv/\n[rookonheroku]: https://github.com/noahhl/rookonheroku\n[rprofile]: https://cran.r-project.org/doc/manuals/r-release/R-intro.html#Customizing-the-environment\n[rproject]: https://www.r-project.org\n[s3]: https://heroku-buildpack-r.s3.amazonaws.com\n[scheduler]: https://addons.heroku.com/scheduler\n[shiny-app]: https://github.com/virtualstaticvoid/heroku-shiny-app\n[shiny]: https://shiny.rstudio.com\n[slugsize]: https://devcenter.heroku.com/articles/slug-compiler#slug-size\n[stack18]: https://devcenter.heroku.com/articles/heroku-18-stack\n[stack20]: https://devcenter.heroku.com/articles/heroku-20-stack\n[tcltk]: https://www.tcl.tk\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprimaryobjects%2Fheroku-buildpack-r-20","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprimaryobjects%2Fheroku-buildpack-r-20","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprimaryobjects%2Fheroku-buildpack-r-20/lists"}