Skip to content

Using the Template

Hugo Gruson edited this page Jul 18, 2023 · 3 revisions

Command line instructions: Create a new Github repository using a template

There's a shortcut to this, which is provided here for people short on time, but the scenic route follows.

Github command line client

Install the Github command line client gh following the instructions for your OS here: https://github.com/cli/cli. Run gh auth login to link your device with your Github account the first time you use the CLI.

Once installed and authenticated, run:

gh repo create epiverse-trace/mypackage --public --template=epiverse-trace/packagetemplate

Clone the repository as usual using your preferred method.

Command line instructions: Create a repo and R package from scratch

Make an R project

Rscript -e 'devtools::create("mypackage")'

or

Rscript -e 'usethis::create_package("mypackage")'

Initialise a git repository

cd mypackage
git init

Create a remote Github repository

Github command line client

Install the Github command line client gh following the instructions for your OS here: https://github.com/cli/cli. Run gh auth login to link your device with your Github account the first time you use the CLI.

Create the package repository in the Epiverse TRACE organisation.

# still in mypackage
gh repo create epiverse-trace/mypackage

Initial commit to main

git push --set-upstream origin main

Get R-related .gitignore

Getting R.gitignore from https://github.com/github/gitignore, and renaming it to .gitignore.

wget is cross platform and should be available on most systems. Alternatives using curl exist.

wget https://raw.githubusercontent.com/github/gitignore/main/R.gitignore
mv R.gitignore .gitignore

Set up R package components

These next steps are from the R command line. If you are prompted to copy or edit text in the terminal (especially if you launched R from the terminal using $ R), you might be in Vim. Exit by typing :wq, and edit these files in a text editor.

  1. Populate fields in the DESCRIPTION and NAMESPACE
# e.g. using data.table
usethis::use_package("data.table")

Actually data.table requires a bit more configuration to use many of its features, such as := and .SD. Use instead:

usethis::use_data_table()
  1. Set up unit testing infrastructure
usethis::use_testthat()

# and a basic test file
usethis::use_test("basic-test")

# code coverage YAML for codecov
usethis::use_coverage("codecov")
  1. Set a licence

We prefer the MIT licence, primarily because it is short and easy to read.

usethis::use_mit_licence()
  1. Make a README page
usethis::use_readme_rmd()

Readme.md can be updated manually from the Readme.Rmd created above, using

devtools::build_readme()

or using a Github Actions setup (see the examples here https://github.com/r-lib/actions/tree/v2-branch/examples).

  1. Set up continuous integration using Github Actions
# to check package installation
usethis::use_github_actions_check_standard()

# to report code coverage results to codecov
usethis::use_github_action("test-coverage")
  1. Set up documentation

a. Document the package as required using

devtools::document()

b. Set up a pkgdown website.

# configure the pkgdown YAML.
# can be saved and edited later
usethis::use_pkgdown()

# build the website using
pkgdown::build_site()

Or set up a Github Actions job using usethis::use_github_action("pkgdown").

Clone this wiki locally