Introduction
Many different source of information were used to put together this template packages and its worth documenting them all for easy review.
- R packages - covers general R package development
- precommit - covers general precommit setups
- r precommit - covers some extra r specific precommits
- pkgdown - for building general packages from R documentation
- change-pkg-name - for thinking of how to change the package name
This template package used these resources to try and give an example that has: 1. Automatic production of code documention 2. Automatic pre-commit running of code checks and tests 3. Some Continuous Integration (CI) / Continuous Deployment (CD) pipelines in Github 4. An automatically built package website 5. Experiments with the R package building process 6. Suitable testthat R examples and linkages for CI / CD 7. Key vignettes showing relevant background information
library(packTemplate)
packTemplate::hello()
#> [1] "Hello, world!"
#> NULL
packTemplate::df_shape_log_message(cars)
#> Dataframe has: 50 rows, 2 columns,
#> 50 rows without missing entries,
#> 2 columns without missing entries
We also think to the set of usethis commands that were involved in setting up this template package for reference.
Please also note that these aren’t all run at once and not all necessarily used in this specific package. i.e some may depend on setting up a github remote not defined in these checks
# initialising a package with version control and a license
::create_package("path_to_package")'
usethis# usethis::create_project() # alternative that creates Rstudio rpoj files
usethis::use_git()
usethis::use_mit_license()
# Set it up to use testing + github
usethis::use_testhat()
usethis::use_readme_rmd() # Adds a .rmd readme file which gets compiled to an readme.md
usethis::use_news_md() # Adds a NEWS.md file for storing notes on version changes and releases
usethis::use_github_links() # Add link of github remote to dscription file
usethis::use_roxygen_md() # Use roxygen with markdown for documentation
# usethis::use_github() # I didn't use this here but can set up a new git repository
# For adding packages in teh dependencies
::use_package("glue")
usethis
# Optional for certain chages
# usethis::rename_files(old, new) # Manages renaming tests, and source files to match new name
# usethis::use_r() to create new r file
# usethis::use_test() to create testing file for the R file
# Setting up many TidyVerse style defaults
::use_tidy_issue_template() # Adds the tidyverse issue template by default. It asks for a repex of the issue
usethis::use_tidy_contributing() # Adds the tidy version contribution guidelines to the package
usethis::use_tidy_coc() # Adds tidyverse code of conduct to the package
usethis
# Add relevant badges to the project - by default added to readme file
::use_lifecycle_badge("experimental")
usethis# use_cran_badge() # Would use if release to CRAN to indicate the latest CRAN release
# Adding github actions for implementing parts of the CI / CD desires
# Lots of good github action examples here: https://github.com/r-lib/actions/tree/v2/examples
::use_github_action("check-standard") # Runs R CMD Check on a few operating systems
usethis# usethis::use_github_action("test-coverage") # Running test-coverage on push - USES EXTERNAL SERVICE, don't run unless code is public
::use_github_action("pr-commands") # To enforce document update + styler use in code on pull requests
usethis::use_pkgdown_github_pages() # Sets up github
usethis::use_github_action("lint-project") # Sets up linting to run on package commit and check for R syntax errors
usethis
# version increments
::use_version(which = "patch")
usethis
# Setting up more examples for people to learn from
# Set some options in the R project to my preferred
::use_blank_slate(scope = "project") # Sets R project to not keep R workspace usethis
The last very important part of this setup is establishing the git pre-commit hooks appropriately.