knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
R Markdown Template for Developing R Package :package:
pkgtemp contains as series of usethis and other commands in an R Markdown that provides a template to kick-start your R package development process. If you want to use your own template from GitHub, this package will facilitate that too.
You should be somewhat familiar with how to create R Package. Checkout these resources to learn more:
R Packages Book by Hadley Wickham and Jenny Bryan.
usethis: a workflow package that pkgtemp relies on.
(pkgtemp assumes that R package is develop in RStudio. If you use other IDE you may need to adapt your workflow accordingly.)
You can install the development version of pkgtemp like so:
# install.packages("remotes") remotes::install_github("Lightbridge-KS/pkgtemp")
Create R Package by:
usethis::create_package("~/path/to/yourpkg")
Create R Markdown Template for package development by:
pkgtemp::use_pkgbuild_rmd()
This will:
Create folder dev/.
Write and open R Markdown file dev/build.Rmd (generate locally)
Go to build.Rmd. You will see 2 types of command in there:
Non-commented commands: are the command for initial setup. I recommend you run at the first visit. They are at the top of R Markdown.
Commented commands: you can choose to run in any order as you like.
# Reset possible options options(usethis.description = list())
# Create a new package ------------------------------------------------- path <- file.path(tempdir(), "yourpkg") usethis::create_package(path) # only needed since this session isn't interactive usethis::proj_activate(path) .old_wd <- setwd(path) # Only in this example # Create Rmd Template for PKG Development pkgtemp::use_pkgbuild_rmd(open = FALSE)
Everyone can have a different package development workflow. This second approach will allows you to use your default template from a file in GitHub.
Here how it works:
Create your own R Markdown template for building package in Github. (for example, mine is here)
Provide a default GitHub URL where pkgtemp will find as your remote template. You'll need to config global option in ~/.Rprofile as follows.
# To edit `~/.Rprofile` usethis::edit_r_profile()
Copy code below to ~/.Rprofile and provide your pkgbuild_url as URL to your default template.
if (interactive() && requireNamespace("pkgtemp", quietly = TRUE)) { pkgtemp::set_github_template_url( pkgbuild_url = "https://github.com/OWNER/REPO/blob/REF/path/to/default-template.Rmd" ) }
use_pkgbuild_rmd() with remote = TRUE.pkgtemp::use_pkgbuild_rmd(remote = TRUE)
Alternatively, If you want to use any other GitHub template just once in a while, provides a url directly.
pkgtemp::use_pkgbuild_rmd(url = "https://github.com/OWNER/REPO/blob/REF/path/to/one-off-template.Rmd")
Last updated: r Sys.Date()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.