templates.Rd
Outputs a template of common annotations and code segments to the console for easy copying and pasting.
templates(type = NULL, val = NULL)
The type of template to return, with options for...
'Function (function documentation);
'Header' (header for a R script);
'Package' (package version);
'Progress' (progress bar for a loop);
'Loop' (a for
loop statement);
'Conditional' (a if
statement);
'Roxygen2' (function documentation using Roxygen2);
'recode' (values for the 'dplyr'
function recode
).
An optional character vector to be used
with type = 'recode'
.
# List of possible inputs to argument
# 'type' for each template
templates()
#> Available template options:
#> - Function
#> - Header
#> - Package version
#> - Progress
#> - Loop
#> - Conditional
#> - Roxygen2
#> - recode
#> - HTML links
#> - Rmd glossary
# Function documentation
templates("Function")
#> # Title
#> #
#> # ...
#> #
#> # @param 'obj_x' An R object.
#> #
#> # @details
#> # Prerequisites:
#> # * The R package '?' (version ?)
#> #
#> # @returns ...
#> #
#> # @examples
#> # Forthcoming
# Header for R script
templates("Header")
#> # Title
#> # Written by Kevin Potter
#> # email: kevin.w.potter@gmail.com
#> # Please email me directly if you
#> # have any questions or comments
#> # Last updated 2024-10-19
#>
#> # Table of contents
#> # 1)
# Package version
templates("Package", "stats")
#> # * The R package 'stats' (version 4.4.0)
# Progress bar for loop
templates("Progress")
#> int_cases <- 10
#> # Create a progress bar using a base R function
#> obj_pb <- txtProgressBar(
#> min = 1, max = int_cases, style = 3
#> )
#>
#> # Loop over cases
#> for (i in 1:n_cases) {
#> # Update the progress bar
#> setTxtProgressBar(obj_pb, i)
#> # Close 'Loop over cases'
#> }
#> close(obj_pb)
# Loop
templates("Loop")
#> # Descriptor
#> for (i in 1:n) {
#> # Do something
#> # Close 'Descriptor'
#> }
# If ... else statement
templates("Conditional")
#> # Descriptor
#> if (value %in% values) {
#> # Do something
#> # Close 'Descriptor'
#> } else {
#> # Do something else
#> # Close else for 'Descriptor'
#> }
# Roxygen2 function documentation
templates("roxygen")
#> #' Title
#> #'
#> #' Description.
#> #'
#> #' @param x ...
#> #'
#> #' @details
#> #'
#> #' @returns Output.
#> #'
#> #' @examples
#> #' # Examples
#> #'
#> #' @export
#>
# HTML internal links
templates("html_links")
# Example table for specifying
# nomenclature and a glossary
# in a .Rmd file
templates("rmd_glossary")