templateFile: Create template file for new function/class/method

View source: R/templateFile.R

templateFileR Documentation

Create template file for new function/class/method

Description

This function can be used to generate template files for new functions, S4 classes or methods.

Usage

templateFile(
  name,
  path = getwd(),
  pck.description = data.frame(Package = "", Author = "", License = "GPL (>= 3)",
    stringsAsFactors = FALSE),
  year = format(Sys.time(), "%Y"),
  params = list(obj = "someClass", ... = "\\code{\\link[somepackage]{somefunction}}"),
  seealso = list(aPackage = "aFunction"),
  return = list(aPackage = "aFunction"),
  type = "function",
  write = FALSE,
  overwrite = FALSE
)

Arguments

name

Character string, name of the function/method/class.

path

Full path to the directory where the file should be added if write=TRUE.

pck.description

Data frame holding the package description. Only the fields "Package", "Author" and "License" are needed/used (see Examples section).

year

Character string, the year to use in the copyright information.

params

A named list of parameters, where the element name is the parameter name and its value is the type of object expected as input. Some objects types are recognized, like "c", "character", "numeric", "logical", "matrix" or "data.frame". If an element is called "...", the value is assumend to point to a function or method where additional arguments are passed to. If type="S4class", this argument is used to define the slots.

seealso

A named list, where element names define packages and values objects of that package to link.

return

A named list, similar to seealso, but generating references for returned objects.

type

Character string, either "function", "S4class", or "S4method", depending on the template you want to create.

write

Logical, if TRUE output will be written to a file in path, otherwise returned as a character string.

overwrite

Logical, if TRUE and the output file already exists, it will be replaced with the generated template. Otherwise you'll just get an error.

Details

Set the parameters to your needs, perhaps setwd into the target directory, and set write=TRUE if you like what you see so far. The result should include a copyright note, insitial roxygen-style documentation and some useful first lines of code, guessed from the provided arguments.

Value

If write=TRUE, writes a file in the path directory. If write=FALSE, returns a character string.

Examples

pckg.dscrptn <- data.frame(
  Package="SquareTheCircle",
  Author="E.A. Dölle <doelle@eternalwondermaths.example.org>",
  License="GPL (>= 3)",
  stringsAsFactors=FALSE
)
cat(
  templateFile(
    name="exampleFunction",
    pck.description=pckg.dscrptn
  )
)

unDocUMeantIt/roxyPackage documentation built on March 9, 2023, 6:31 p.m.