This repository is a template repository for creating a Teal Insights R package. It includes renv for dependency management, testthat for tests, lintr for linting, and pkgdown for building a documentation website and publishing it to Github Pages.
Members of the Teal Insights organization can use our internal command-line tool RpackageCreator to create a new package from this template. See the README in that repository for instructions.
For manual setup, clone this repository, navigate into the project folder, and disconnect your cloned repository from the template repository:
# Replace {newpackagename} with the name of your new package
git clone https://github.com/Teal-Insights/RpackageTemplate.git {newpackagename}
cd {newpackagename}
git remote remove origin
Find and replace all placeholders ‘packagename’, ‘packagetitle’, ‘packagedescription’, and ‘packagelicense’ with the appropriate values for your package.
Edit the Authors@R
field in the DESCRIPTION
file to reflect your
package’s authorship. Also edit the URL and BugReports fields to point
to your package’s Github repo and Github Pages documentation website.
Commit changes and publish to a new repository:
git add .
git commit -m "Initial commit"
# Replace {your-github-username} and {newpackagename}
gh repo create {your-github-username}/{newpackagename} --private --source=. --push
Open an R terminal in the project folder and install the dependencies:
renv::restore()
usethis::use_r(name=)
creates a pair of source and test files with the selected filename- If the source file already exists and is open in your IDE, you can
instead do
usethis::use_test()
to create an appropriately named test file
usethis::use_package(package)
adds the named package to DESCRIPTION dependenciesusethis::use_dev_package(package, type="Suggests")
adds a development dependency (won’t be installed for end-users)pak::pkg_install("github::username/package")
to add a Github dependency (sinceusethis::use_package(package, remote="github::username/package")
seems not to work, even though it should)usethis::use_import_from(package, fun=)
adds a single function import to the roxygen2 docs
renv::init()
sets up the project’s file system for dependency management with renvrenv::install()
installs all dependencies listed in DESCRIPTION, including Suggests/development dependenciesrenv::snapshot()
regenerates the lockfile to match currently installed dependencies, excluding Suggests/development dependenciesrenv::update()
updates all package dependencies to latest versionsrenv::restore()
installs all dependencies declared in the lockfile
usethis::use_data(some_dataframe, name="filename")
saves a data object to “data/filename.rda” for use as a package exportusethis::use_data_raw("dataset_name")
creates an empty R script in the “data-raw” directory—this is where you put any automation scripts that are used for generating/updating the exported dataset but that you don’t want to export to the end-user
usethis::use_vignette("vignette_name")
creates a new vignette template in the “vignettes” directoryusethis::use_article("article_name")
creates a new article template in the “vignettes/articles” directoryusethis::use_package_doc()
creates a package-level documentation file
devtools::document()
generates documentation files from roxygen2 commentsdevtools::build_readme()
renders the .md README from the .Rmd READMEdevtools::build()
builds the package into a .tar.gz filedevtools::install()
installs the package locallydevtools::check()
runs R CMD check on the packagedevtools::test()
runs all tests in the package
pkgdown::build_site()
builds a documentation website for the packagedevtools::build_manual()
builds a PDF manual for the packagedevtools::build_vignettes()
builds all vignettes in the package
usethis::use_version(which=NULL,push=NULL)
updates your package’s
version number in DESCRIPTION and commits the change.
which
: Controls which part of the version number to increment- “major”: First number (0.0.1 -> 1.0.0)
- “minor”: Second number (0.0.1 -> 0.1.0)
- “patch”: Third number (0.0.1 -> 0.0.2)
- “dev”: Adds development suffix (0.0.1 -> 0.0.1.9000)
push
: When TRUE, automatically pushes the version bump commit to remote
devtools::release()
guides you through the CRAN submission process- Update
cran-comments.md
with any necessary explanations for CRAN maintainers - Use
devtools::check_rhub()
to test on R-hub before submission