- Ubuntu 22.04 base image.
- R 4.4.x via rig.
- Package dependencies are specified in a
DESCRIPTIONfile, asDependes:orImports:. - Package dependencies for tests are specified in
DESCRIPTION, underSuggests:. - The
teststage ofDockerfileruns the tests. - The
prodstage ofDockerfileruns the tests cases viatestthat::test_local().
See the https://github.com/r-hub/cran-metadata project that uses these dev container templates.
Another example project that uses a newer version of the gh-script
template is https://github.com/gaborcsardi/myweek.
gh-scriptAn R script to run with a scheduler on GitHub Actions.
- From the command palette, select "Dev Containers: Add Dev Container Configuration Files...".
- Select "Add configuration to workspace" or "Add configuration to user data folder".
- Then use
ghcr.io/r-lib/devcontainer-templates/gh-script:latestas the template to apply. - Select additional features. None are required currently.
- When including optional dependencies you may want to include some GitHub actions workflows to deploy the script to GitHub Actions.
- Create a
DESCRIPTIONfile with package name and version. E.g.Package: mypackage Version: 1.0.0 - You now select "Rebuild and Reopen in Container" to start the project in in the dev container.
- Install the devcontainer cli. On macOS you can use
brew install devcontainer - Before installing the template, I recommend to commit your changes, because the template might overwrite some of your files.
- Install the template:
devcontainer templates apply -w . -t \ ghcr.io/r-lib/devcontainer-templates/gh-script:latest - Create a
DESCRIPTIONfile with package name and version. E.g.Package: mypackage Version: 1.0.0 - Build the template:
devcontainer build --workspace-folder . - Start the container:
devcontainer up --workspace-folder .
Use the template as usual in tools that natively support dev containers, e.g. VS Code, GitHub Codespaces, VSCodium + Devpod, etc.
To use R projects with these templates from Poisitron, for now there is a bit of extra legwork:
- Use a random port for SSH (optional).
echo PORT=2222 >> .env - Start the container:
devcontainer up --workspace-folder . - Connect from Positron. From the command palette choose
'Remote-SSH: Connect to Host...' or 'Remote-SSH: Connect Current Window
to Host...'. The connection string is
(Use the port you set in
root@localhost:2222.env. The default is 2222 if you don't have.env.) - Open the
/workspaces/cran-metadatafolder.
- Reconnecting from Positron: to reconnect to a running dev container, the easiest is to select the remote folder from the list of recently opened project on the top right. If it is not there, use the last two steps of the previous section.
- Stopping: Positron does not stop the container when it disconnects. The
devcontainer cli also cannot stop it currently. To stop the container
call docker directly:
docker stop cran-metadata-r-app-1 - Restarting: to restart a stopped container call
devcontainer up --workspace-folder . - Rebuilding: to rebuild a container stop it and delete it before you
build it again:
docker stop cran-metadata-r-app-1 docker rm cran-metadata-r-app-1 devcontainer up --workspace-folder .
MIT (c) Posit, PBC