{"id":13857508,"url":"https://github.com/virtualstaticvoid/heroku-buildpack-r","last_synced_at":"2025-07-13T21:32:57.057Z","repository":{"id":2476873,"uuid":"3449857","full_name":"virtualstaticvoid/heroku-buildpack-r","owner":"virtualstaticvoid","description":"Heroku buildpack for R - Makes deploying R on Heroku easy","archived":false,"fork":false,"pushed_at":"2023-03-16T10:16:35.000Z","size":17349,"stargazers_count":305,"open_issues_count":4,"forks_count":236,"subscribers_count":17,"default_branch":"main","last_synced_at":"2024-08-06T03:04:02.488Z","etag":null,"topics":["heroku","heroku-buildpack","multiple-buildpacks","packrat","plumber","plumber-applications","r","renv","shiny","shiny-applications"],"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/virtualstaticvoid.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}},"created_at":"2012-02-15T13:52:14.000Z","updated_at":"2024-03-22T12:05:01.000Z","dependencies_parsed_at":"2023-07-05T17:15:20.520Z","dependency_job_id":null,"html_url":"https://github.com/virtualstaticvoid/heroku-buildpack-r","commit_stats":{"total_commits":281,"total_committers":5,"mean_commits":56.2,"dds":0.05693950177935947,"last_synced_commit":"24cfc8e35ff203eef808e7f3a8a6bd3009aac0df"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virtualstaticvoid%2Fheroku-buildpack-r","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virtualstaticvoid%2Fheroku-buildpack-r/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virtualstaticvoid%2Fheroku-buildpack-r/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virtualstaticvoid%2Fheroku-buildpack-r/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/virtualstaticvoid","download_url":"https://codeload.github.com/virtualstaticvoid/heroku-buildpack-r/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225920367,"owners_count":17545476,"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":["heroku","heroku-buildpack","multiple-buildpacks","packrat","plumber","plumber-applications","r","renv","shiny","shiny-applications"],"created_at":"2024-08-05T03:01:39.163Z","updated_at":"2025-07-13T21:32:57.045Z","avatar_url":"https://github.com/virtualstaticvoid.png","language":"R","readme":"# Heroku Buildpack: R\n\n[![CI](https://github.com/virtualstaticvoid/heroku-buildpack-r-build2/actions/workflows/main.yml/badge.svg)](https://github.com/virtualstaticvoid/heroku-buildpack-r-build2/actions/workflows/main.yml)\n\nThis is a [Heroku Buildpack][buildpacks] for applications which use [R][rproject] for\nstatistical computing and [CRAN][cran] for R packages.\n\nThe buildpack supports the [heroku-20][stack20][^20support], [heroku-22][stack22][^22support]\nand [heroku-24][stack24][^24support] stacks.\n\nIt also includes support for the [Packrat][packrat] and [renv][renv] package managers, and\nthe [Shiny][shiny] and [Plumber][plumber] web application frameworks.\n\n### Heroku Stack and R Versions\n\nThe following table lists the available combinations of Heroku Stack and R version.\nThey are [built][build2] periodically as and when the [Debian R packages][cloud-r-project]\nare available.\n\n| R / Stack | `20`[^20support] | `22`[^22support] | `24`[^24support] |\n|:---------:|:---:|:---:|:---:|\n| `4.0.0`   | □ |   |   |\n| `4.0.5`   | □ |   |   |\n| `4.1.2`   | □ | □ |   |\n| `4.1.3`   | □ |   |   |\n| `4.2.0`   |   | □ |   |\n| `4.2.1`   | ■ | ■ |   |\n| `4.4.2`   |   |   | ■ |\n\nLegend:\n\n* `■` = default version for given stack\n* `□` = available\n* empty = no package available\n\nThe default R version can be overridden by setting the `R_VERSION` environment variable.\n\n```bash\nheroku config:set R_VERSION=4.0.0\n```\n\n## Usage\n\nThe buildpack's name is [`vsv/heroku-buildpack-r`][bpurl]. Provide it when creating your\napplication on Heroku as follows:\n\n```bash\nheroku create --buildpack vsv/heroku-buildpack-r\n```\n\nYou can add it to an existing application using the `buildpacks:add` command, as follows:\n\n```bash\nheroku buildpacks:add vsv/heroku-buildpack-r\n```\n\nAlternatively, you can use the Git URL of this repository, together with the branch name.\n\n```\nhttps://github.com/virtualstaticvoid/heroku-buildpack-r.git#main\n```\n\nThe buildpack will detect your application makes use of R if it has one (or more)\nof 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,\nand if `packrat/init.R` or `renv/activate.R` files are found, the respective package manager\nwill 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\npackage dependencies and their respective versions, so the `init.R` file isn't required\nif you use `packrat` or `renv`.\n\nThe following example `init.R` file can be used. Provide the package names you want to\ninstall to the `my_packages` list variable:\n\n```R\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, clean=TRUE, quiet=TRUE)\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\nspecific version is required, or it is not a publicly published package. See\n[local-packages](test/local-packages) for an example.\n\n```R\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\ndirectory, 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\nincluded 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\npackage names you want to install as arguments to the helper:\n\n```R\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\nadditional system packages, however this functionality is going to be _deprecated_ in\nfuture as it isn't a foolproof solution.\n\nIt is based on the same technique as used by the [heroku-buildpack-apt][bpapt] buildpack\nto install Ubuntu packages using `apt-get`.\n\nThere are various technical and security reasons why it is no longer recommended,\nso your mileage may vary.\n\nIf any of your R packages dependend on system libraries which aren't\n[included by Heroku][herokupkgs], such as `libgmp`, `libgomp`, `libgdal`, `libgeos`\nand `libgsl`, you should use the Heroku [container stack][container-stack] together\nwith [heroku-docker-r][heroku-docker-r] instead.\n\n## R Applications\n\n### Heroku Console\n\nYou can run the R console application as follows:\n\n```bash\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```bash\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\ninstall additional R packages. The Shiny package does not need to be installed, as it is\nincluded 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\nto configure Shiny and the host must be `0.0.0.0`.\n\n```R\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\nto install additional R packages. The Plumber package does not need to be installed, as it\nis 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\nconfigure Shiny and the host must be `0.0.0.0`.\n\n```R\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### Slug Compilation vs Runtime use of `chroot`\n\nThis version of the buildpack still uses a [fakechroot][fakechroot] during slug compilation,\nto compile R packages which may include C or Fortran code. However it no longer uses the\n`chroot` at runtime so it can work better in scenarios where other language buildpacks are\nused, 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\nto use `fakechroot`, `fakeroot` or `chroot`. Wrappers of these commands are included and\nthey 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\ntypes 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\noverride the default process types and/or their command lines, within the `run` section.\nThis is typically required if you are using multiple buildpacks.\n\nFor example, the following `heroku.yml` file defines the commands for the `web`\nand `console` processes.\n\n```yaml\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;\nso 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\nto 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\n[`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\nbe 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\nperforming configuration tasks.\n\nPlease _do not_ use it to install R packages, since it may cause problems during deployment\n(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\nthe `CRAN_MIRROR` environment variable.\n\nE.g. Override the URL by setting the variable as follows.\n\n```bash\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\nvia the `heroku repo:purge_cache` command.\n\nSee the [purge-cache][purge] documentation for more information.\n\n## Build Output Verbosity\n\nIn previous versions of the buildpack, the full output of `install.packages()` was emitted\nduring slug compilation, which lead to very verbose output and made it hard to spot issues\nin some instances. Packages are now installed with `quiet=TRUE` option set by default.\n\nTo restore the previous behaviour, set the `PACKAGE_INSTALL_VERBOSE` environment variable\nto a value of `1` before deploying your application:\n\n```bash\nheroku config:set PACKAGE_INSTALL_VERBOSE=1\n```\n\nTo revert the setting use the `config:unset` command:\n\n```bash\nheroku config:unset PACKAGE_INSTALL_VERBOSE\n```\n\n## Hacking\n\nTo enable debug outputs during deployment, set the `BUILDPACK_DEBUG` environment variable.\n\n```bash\nheroku config:set BUILDPACK_DEBUG=1\n```\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\u003c!-- footnotes --\u003e\n\n[^20support]: Heroku-20 is based on Ubuntu 20.04. It will be supported through April 2025.\n[^22support]: Heroku-22 is based on Ubuntu 22.04. It will be supported through April 2027.\n[^24support]: Heroku-24 is based on Ubuntu 24.04. It will be supported through April 2029.\n\n\u003c!-- links --\u003e\n\n[bpapt]: https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-apt\n[bpurl]: https://elements.heroku.com/buildpacks/virtualstaticvoid/heroku-buildpack-r\n[build2]: https://github.com/virtualstaticvoid/heroku-buildpack-r-build2\n[buildpacks]: https://devcenter.heroku.com/articles/buildpacks\n[cloud-r-project]: https://cloud.r-project.org/bin/linux/ubuntu/\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]: https://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[stack20]: https://devcenter.heroku.com/articles/heroku-20-stack\n[stack22]: https://devcenter.heroku.com/articles/heroku-22-stack\n[stack24]: https://devcenter.heroku.com/articles/heroku-24-stack\n[tcltk]: https://www.tcl.tk\n","funding_links":[],"categories":["R"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvirtualstaticvoid%2Fheroku-buildpack-r","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvirtualstaticvoid%2Fheroku-buildpack-r","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvirtualstaticvoid%2Fheroku-buildpack-r/lists"}