document_data: Create dataset documentation

Description Usage Arguments

View source: R/document_data.R

Description

This function generates R documentation for one or more datasets. You need to provide a data frame with a description of each dataset and a data frame with a description of each variable. Whenever you update these data frames, you can easily regenerate the R documentation without making the changes in multiple places. Running this function generates one .R file per dataset and saves these files in the folder indicated by the path argument. If you're developing an R package, this path should be to the R/ folder in your package directory. After you run document_data() to produce an .R file for each dataset, you can run roxygen2 using devetools::document() to generate a .Rd (R documentation) file for each dataset. These .Rd files will be saved to the man/ folder, as usual.

Usage

1
2
3
4
5
6
7
8
document_data(
  file_path,
  variables_input,
  datasets_input,
  include_variable_type = FALSE,
  author = NULL,
  package = NULL
)

Arguments

file_path

The path to the folder where the output file should be saved. If you're developing an R package and you're working directory is set to the project directory, this argument should be "R/".

variables_input

A data frame containing infromation on each variable. This data frame must include: (1) a variable called dataset, where each dataset maps exactly to the datasets in the dataset variable in the datasets_input data frame; and (2) a variable called description that is a description of each variable. Text wrapped in braces will be formatted as code. Optionally, the data frame can include a variable called type that indicates the type of each variable (e.g., numeric, string, etc.). If this variable is included, and the include_variable_type argument is set to TRUE, then the variable type will be included at the beginning of each variable description.

datasets_input

A data frame containing information on each dataset. This data frame must include: (1) a variable called dataset that is the name of each dataset, which will be used as the heading for each dataset section; (2) a variable called label that is a short label for each dataset (one line), which will be used as the subheading for each dataset section; and (3) a variable called description that is a description of each dataset, which will be included before the description of each variable. Text wrapped in braces will be formatted as code. The dataset names should be valid R object names.

include_variable_type

A logical value indicating whether to include the type of the variable in the variable description. The variables_input data frame must have a variable called type or you will get an error.

author

Optional. A string or string vector indicating the name of the package author(s). If provided, these names will be included in the header of each .R file produced.

package

Optional. A string indicating the name of the package that the data will be distributed in. If provided, the name of the package will be included in the header of each .R file produced.


jfjelstul/codebookr documentation built on Dec. 20, 2021, 11:07 p.m.