Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 40d1a2d

Browse files
authoredSep 3, 2024··
Initial commit
0 parents  commit 40d1a2d

File tree

4 files changed

+168
-0
lines changed

4 files changed

+168
-0
lines changed
 

‎.devcontainer/devcontainer.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Config options: https://github.com/rocker-org/devcontainer-templates/tree/main/src/r-ver
2+
{
3+
"name": "R Package Dev Prebuilt (rocker/r-ver base)",
4+
// Image to pull when not building from scratch.
5+
// See .github/devcontainer/devcontainer.json for build details
6+
// and .github/workflows/pre-build-devcontainer.yml for how the
7+
// image is built using GitHub Actions/CI
8+
"image": "ghcr.io/coatless-devcontainer/r-pkg:latest"
9+
}
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Config options: https://github.com/rocker-org/devcontainer-templates/tree/main/src/r-ver
2+
{
3+
"name": "R Package Dev (rocker/r-ver base)",
4+
"image": "ghcr.io/rocker-org/devcontainer/r-ver:4.4",
5+
// Add software
6+
"features": {
7+
// Rig configuration: https://github.com/rocker-org/devcontainer-features/blob/main/src/r-rig/README.md
8+
"ghcr.io/rocker-org/devcontainer-features/r-rig:1": {
9+
"installDevTools": true,
10+
"installRadian": true,
11+
"installVscDebugger": true,
12+
"installRMarkdown": true,
13+
"vscodeRSupport": "full"
14+
}
15+
},
16+
"customizations": {
17+
"vscode": {
18+
// Ensure VS Code extensions for R are present
19+
"extensions": [
20+
// R Extensions
21+
"rdebugger.r-debugger",
22+
"reditorsupport.r",
23+
// Quarto
24+
"quarto.quarto",
25+
// LLM
26+
"GitHub.copilot"
27+
]
28+
},
29+
// Customize R settings
30+
"settings": {
31+
"editor.wordWrap": "wordWrapColumn",
32+
"r.rterm.linux": "/usr/local/bin/radian",
33+
"r.bracketedPaste": true,
34+
"r.plot.useHttpgd": true,
35+
// Settings by language
36+
"[r]": {
37+
"editor.wordSeparators": "`~!@#%$^&*()-=+[{]}\\|;:'\",<>/?",
38+
"editor.defaultFormatter": "REditorSupport.r",
39+
"editor.snippetSuggestions": "top"
40+
},
41+
"[rmd]": {
42+
"editor.defaultFormatter": "REditorSupport.r",
43+
"editor.snippetSuggestions": "top"
44+
},
45+
"[quarto]": {
46+
"editor.defaultFormatter": "quarto.quarto",
47+
"editor.snippetSuggestions": "top"
48+
},
49+
// Enable suggestions
50+
"github.copilot.enable": {
51+
"quarto": true,
52+
"*": true
53+
}
54+
}
55+
},
56+
// Enable pak using system package manager
57+
// https://github.com/rocker-org/devcontainer-features/blob/main/src/r-rig/README.md#install-r-packages-via-pak
58+
"remoteEnv": {
59+
"PKG_SYSREQS": "true"
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: 'build'
2+
on: # rebuild any PRs and main branch changes
3+
pull_request:
4+
branches:
5+
- main
6+
push:
7+
branches:
8+
- main
9+
workflow_dispatch: {}
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write
17+
env:
18+
CONTAINER_OWNER: ${{ github.repository_owner }}
19+
CONTAINER_NAME: ${{ github.event.repository.name }}
20+
steps:
21+
22+
- name: Checkout (GitHub)
23+
uses: actions/checkout@v3
24+
25+
- name: Login to GitHub Container Registry
26+
uses: docker/login-action@v2
27+
with:
28+
registry: ghcr.io
29+
username: ${{ env.CONTAINER_OWNER }}
30+
password: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Pre-build dev container image
33+
uses: devcontainers/ci@v0.3
34+
with:
35+
subFolder: .github
36+
imageName: ghcr.io/${{ env.CONTAINER_OWNER }}/${{ env.CONTAINER_NAME }}
37+
cacheFrom: ghcr.io/${{ env.CONTAINER_OWNER }}/${{ env.CONTAINER_NAME }}
38+
push: always

‎README.md

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# r-pkg
2+
3+
This repository houses a devcontainer that setups an R package development environment. The container is setup to work with [GitHub Codespaces](https://github.com/features/codespaces) to instantly have a cloud-based developer workflow.
4+
5+
You can try out the Codespace by clicking on the following button:
6+
7+
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/coatless-devcontainer/r-pkg?quickstart=1)
8+
9+
> [!NOTE]
10+
>
11+
> Codespaces are available to Students and Teachers for free [up to 180 core hours per month](https://docs.github.com/en/education/manage-coursework-with-github-classroom/integrate-github-classroom-with-an-ide/using-github-codespaces-with-github-classroom#about-github-codespaces)
12+
> through [GitHub Education](https://education.github.com/). Otherwise, you will have
13+
> [up to 60 core hours and 15 GB free per month](https://github.com/features/codespaces#pricing).
14+
15+
Or, you can press the template button to create a new repository with the same setup so that you
16+
can work locally on the devcontainer:
17+
18+
[![Use this template](https://img.shields.io/badge/Use%20this%20template-Create%20new%20repository-blue?logo=github)](https://github.com/coatless-devcontainer/r-pkg/generate)
19+
20+
This will create a fork of the repository that can be worked on inside a local copy of
21+
[Visual Studio Code](https://code.visualstudio.com/) through the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers). With the extension installed, you can open the repository in a container by pressing `F1` (to bring up command palette) and typing `Dev Container: Reopen in Container`.
22+
23+
Lastly, you can directly obtain the underlying container image by typing in Terminal:
24+
25+
```sh
26+
docker pull ghcr.io/coatless-devcontainer/r-pkg:latest
27+
```
28+
29+
## Quick start
30+
31+
Run the following series of commands inside of R once the container opens. Make sure to change `"name-of-package"` to your current package name.
32+
33+
```r
34+
usethis::create_package("name-of-package")
35+
usethis::use_package_doc()
36+
usethis::use_agpl3_license()
37+
usethis::use_testthat()
38+
usethis::use_github_action("check-standard")
39+
usethis::use_pkgdown_github_pages()
40+
```
41+
42+
## Resources
43+
44+
- [Manual: Writing R extensions](https://cran.r-project.org/doc/manuals/r-release/R-exts.html)
45+
- [Textbook: R Packages](https://r-pkgs.org/)
46+
- [usethis](https://usethis.r-lib.org/)
47+
- [devtools](https://devtools.r-lib.org/)
48+
49+
## Developer notes
50+
51+
This repository uses a pre-built container strategy to have GitHub Actions build and, then, store the devcontainer in [GitHub's Container Repository](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry).
52+
53+
We place the main logic of the devcontainer in [`.github/.devcontainer/devcontainer.json`](https://github.com/coatless-devcontainer/r-pkg/blob/main/.github/.devcontainer/devcontainer.json). From there, we use [`.github/workflows/pre-build-devcontainer.yml`](https://github.com/coatless-devcontainer/r-pkg/blob/main/.github/workflows/pre-build-devcontainer.yml) to build and publish the devcontainer onto GitHub's Container repository for the organization. Then, the repository's [`.devcontainer/devcontainer.json`](https://github.com/coatless-devcontainer/r-pkg/blob/main/.devcontainer/devcontainer.json) pulls the pre-built image.
54+
55+
> [!IMPORTANT]
56+
>
57+
> Make sure to specify the permissions as stated in the GitHub Actions workflow linked above
58+
> and for organizations please make sure to have the organization's container registry enabled.
59+
>
60+
> For more information, see [GitHub's Container Registry documentation](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry).

0 commit comments

Comments
 (0)
Please sign in to comment.