tldrExample exports several simple functions (multiply()
,
divide()
, …) with
tldr-style
documentation:
Looking at /R/multiply.R
, we can see how
tldr
documentation files are created:
#' Safe multiplication of numeric vectors
#'
#' @param a First element to be multiplied
#' @param b Second element to be multiplied
#' @paramtldr a Multiplier
#' @paramtldr b Multiplicand
#'
#' @return A numeric vector
#' @export
#'
#' @exampletldr Multiply scalars together:
#' \code{multiply(1, 2)}
#'
#' @exampletldr Multiply vectors together:
#' \code{multiply(1:10, rep(2, 10))}
#'
#' @examples
#' multiply(1, 2)
#' multiply(1:10, rep(2, 10))
multiply <- function(a, b) {
if (!is.numeric(a)) stop("a must be numeric")
if (!is.numeric(b)) stop("b must be numeric")
if (length(a) != length(b)) stop("a and b must be vectors of the same length")
a * b
}
tldr_roclet()
from
tldr creates
.Rd files based on relevant tags in the Roxygen skeleton (including the
new @paramtldr
and @exampletldr
). These .Rd files are written to the
/inst/tldr/
directory. Once the package is installed,
tldr:::tldr_help()
and tldr:::tldr_package()
are able to find the
relevant files which are turned into console output by
tldr:::Rd2tldr()
.
This process is inspired by the help()
function—for those who are
interested, I have a
blog
post in which I go through how ?
and help()
work in detail.
tldr and tldrExample are both in very early stages and are not suitable for use as tools by R users and developers. That being said, if you are interested in installing them you can install the development versions from GitHub with:
# install.packages("devtools")
devtools::install_github("jamesotto852/tldr")
devtools::install_github("jamesotto852/tldrExample")