README.md

pkgtemp

Lifecycle:
experimental R-CMD-check

R Markdown Template for Developing R Package :package:

Goal

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.

Prerequisites

You should be somewhat familiar with how to create R Package. Checkout these resources to learn more:

(pkgtemp assumes that R package is develop in RStudio. If you use other IDE you may need to adapt your workflow accordingly.)

Installation

You can install the development version of pkgtemp like so:

# install.packages("remotes")
remotes::install_github("Lightbridge-KS/pkgtemp")

Templates

Workflow

Create R Package by:

usethis::create_package("~/path/to/yourpkg")

Create R Markdown Template for package development by:

pkgtemp::use_pkgbuild_rmd()

This will:

Go to build.Rmd. You will see 2 types of command in there:

Example

# Create a new package -------------------------------------------------
path <- file.path(tempdir(), "yourpkg")
usethis::create_package(path)
#> ✔ Creating '/var/folders/ry/z9m8k9cs4594pv3458npy1zw0000gn/T/RtmpU7eQdS/yourpkg/'
#> ✔ Setting active project to '/private/var/folders/ry/z9m8k9cs4594pv3458npy1zw0000gn/T/RtmpU7eQdS/yourpkg'
#> ✔ Creating 'R/'
#> ✔ Writing 'DESCRIPTION'
#> Package: yourpkg
#> Title: What the Package Does (One Line, Title Case)
#> Version: 0.0.0.9000
#> Authors@R (parsed):
#>     * First Last <first.last@example.com> [aut, cre] (YOUR-ORCID-ID)
#> Description: What the package does (one paragraph).
#> License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a
#>     license
#> Encoding: UTF-8
#> Roxygen: list(markdown = TRUE)
#> RoxygenNote: 7.1.2
#> ✔ Writing 'NAMESPACE'
#> ✔ Setting active project to '<no active project>'

# only needed since this session isn't interactive
usethis::proj_activate(path)
#> ✔ Setting active project to '/private/var/folders/ry/z9m8k9cs4594pv3458npy1zw0000gn/T/RtmpU7eQdS/yourpkg'
#> ✔ Changing working directory to '/var/folders/ry/z9m8k9cs4594pv3458npy1zw0000gn/T/RtmpU7eQdS/yourpkg/'
.old_wd <- setwd(path) # Only in this example

# Create Rmd Template for PKG Development
pkgtemp::use_pkgbuild_rmd(open = FALSE)
#> ✔ Creating 'dev/'
#> ✔ Writing 'dev/build.Rmd'
#> ✔ Adding '^dev$' to '.Rbuildignore'
#> • Edit 'dev/build.Rmd'

Custom Template

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:

# 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"
  )
}
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: 2022-05-03



Lightbridge-KS/pkgtemp documentation built on May 10, 2022, 7:33 p.m.