labelsTemplate: Generate the code to alter the labels in a data frame.

Description Usage Arguments Author(s) Examples

View source: R/labelsTemplate.R

Description

Using labels from the label functions in Hmisc can be useful in clarifying reports and making them more readable to investigators. In large data frames, however, it can be tedious to write out the label(df$var) <- '' part of the code for every variable. labels.template prints the necessary code to the console for a quick copy and paste of all of the variables. Options are provided for sorting the variable names alphabetically, and for retaining their current values in the template.

Usage

1
labelsTemplate(data, sort = FALSE, retain.current = TRUE, prefix = TRUE)

Arguments

data

The data frame for which the labels template should be written.

sort

Logical. If FALSE (default), variables appear in the same order as they appear in the data frame. If TRUE, variables are listed in alphabetical order.

retain.current

Logical. If TRUE, the current values in the labels attribute is printed with the template. If FALSE, all labels are given an empty character set.

prefix

Logical. When TRUE, the commands are printed as Hmisc::label. This is necessary if the Hmisc package is not loaded into the workspace.

Author(s)

Benjamin Nutter

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
library(Hmisc)

mtcars2 <- mtcars # make a copy of mtcars data set

label(mtcars2$am) <- "Automatic Transmission"
label(mtcars2$cyl) <- "Number of Cylinders"

labelsTemplate(mtcars2)
labelsTemplate(mtcars2, sort=TRUE)
labelsTemplate(mtcars2, retain.current=FALSE)

nutterb/Bluegrass documentation built on May 24, 2019, 10:50 a.m.