GetDatLabel: Add, remove, and get dataset, variable, and value value

Description Usage Arguments Details Value Examples

Description

A set of functions that allow the user to document the variables and associated value in a datset. The user has the option to add or remove both variable and value value as well as return the current value. Creating these value is useful in the other functions in the TableRExtracts package.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
GetDatLabel(df)

GetDatDescrip(df)

GetVarLabel(df, index)

GetVarLabels(df)

GetVarDescrip(df, index)

GetValLabel(df, index, val)

GetValLabels(df, index)

GetLabel(df, index, val = NA)

AddDatLabel(df) <- value

AddDatDescrip(df) <- value

AddVarLabel(df, index) <- value

AddVarLabels(df, stop.null = FALSE) <- value

AddVarDescrip(df, index) <- value

AddVarDescrips(df) <- value

AddValLabel(df, index) <- value

AddValLabels(df) <- value

RemoveDatLabel(df)

RemoveDatDescrip(df)

RemoveVarLabel(df) <- value

RemoveVarDescrip(df) <- value

RemoveValLabel(df) <- value

Arguments

df

a tibble

index

either the name of a column/variable or index number

val

specific value of a variable for which a value is to be returned

value

variable value name as character vector

stop.null

optional argument that when true will stop function execution if a variable listed in value does not exist in df

Details

Labels for elements of a datset are set using attributes (see attributes). There are three main types of labels that can be set (attribute name in parentheses):

Several prefixes, bodies, and suffixes are used throughout with function names to allow for straightforward understanding of the utility of each function. Functions then are of the form PrefixBodySuffix.

Prefixes include the following:

Bodies include the following:

Suffixes include the following:

Further, plural suffixes allow for setting value or texts for more than one variable in a single call by iteratively calling the non-plural version of the function.

Variable labels:

Variable labels are set using AddVarLabel() and the arguments must include the dataset as a tibble (df), the name of the variable as a character or a number that refers to its position in the dataset (index), and the value as a character vector (value). This label will be passed to extracts when the variable is included and is ideal for referencing the variable in a table.

Variable texts are set using AddVarDescrip() and includes the same arguments as with AddVarlabel(). This text will be inlcuded in a codebook created for the dataset when the associated variable is inlcuded.

value value:

value value are set

Value

No return for functions with Add or Remove Functions with Get return a character vector.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
### Add datasert label
AddDatLabel(college_grads) <- "College Graduate Earnings"
AddDatDescrip(college_grads) <-
   "Basic earnings and labor force information for recent college graduates"

### Add variable label either by variable name or location in the dataset
AddVarLabel(college_grads, "Total") <- "Total number of people with major"
AddVarLabel(college_grads, 3) <- "Total number of people with major"
AddVarLabels(college_grads) <- c("Total" = "Total number of people with major",
                                 "Men" = "Male graduates",
                                 "Women" = "Female graduates")

### Add value labels
AddValLabel(college_grads, "Major_category2") <-
       list(vals = c(1, 2, 3, 4, 5, 6),
            labs = c("Business, Education, and Communication",
                     "Education", "Health", "Natural Sciences",
                     "Social Sciences and Art", "Other"))
lst <- list("Major_category2" = list(vals = c(1, 2, 3, 4, 5, 6),
                                     labs = c("Business, Education, and Communication",
                                     "Education",
                                     "Health",
                                     "Natural Sciences",
                                     "Social Sciences and Art",
                                     "Other")),
            "Major_category" = list(vals = seq.int(from = 1, to = 16, by = 1),
                                    labs = c("Agriculture & Natural Resources",
                                           "Arts",
                                           "Biology & life Science",
                                           "Business",
                                           "Communications & Journalism",
                                           "Computers & Mathematics",
                                           "Education",
                                           "Engineering",
                                           "Health",
                                           "Humanities & Liberal Arts",
                                           "Industrial Arts & Consumer Services",
                                           "Interdisciplinary",
                                           "Law & Public Policy",
                                           "Physical Sciences",
                                           "Psychology & Social Work",
                                           "Social Science")))

AddValLabels(college_grads) <- lst

### Return variable and value value
### Two ways to return, either by specifying Var or Val directly
### or indirectly through the Getlabel() function
GetVarLabel(college_grads, "Total")
GetValLabel(college_grads, "Major_category2", 1)
GetLabel(college_grads, "Total")
GetLabel(college_grads, "Major_category2", 1)

### Remove variable and value value
RemoveVarLabel(college_grads) <- "Total"
RemoveValLabel(college_grads) <- "Major_category2"

ingels11/TableRExtracts documentation built on May 23, 2019, 8:50 a.m.