Title: | Label Data Using a YAML Codebook |
---|---|
Description: | A light-weight framework for labeling coded data using a codebook saved as YAML text file. |
Authors: | Nick Williams [aut, cre] |
Maintainer: | Nick Williams <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2025-02-26 05:01:04 UTC |
Source: | https://github.com/nt-williams/codebreak |
Decode and label data using a codebook saved as a YAML text file.
path
Path to a YAML text file.
codebook
The codebook.
new()
Import a YAML codebook
Codebook$new(path = "codebook.yml")
path
The path to the YAML codebook.
A new 'Codebook' object.
Codebook$new(system.file("codebook.yml", package = "codebreak"))
decode()
Decode data.
Codebook$decode( data, label = FALSE, as_labelled = FALSE, .include = NULL, .exclude = NULL )
data
The data to decode.
label
Should column names also be renamed according to codebook labels?
as_labelled
Should the codebook be applied using the labelled package?
.include
An optional character vector of column names to apply the codebook to.
.exclude
An optional character vector of column names to not apply
the codebook to. Ignored if .include
is specified.
An updated copy of data
.
ex <- data.frame( x = c(1, 2, 5, 3, 4), y = c(0, 1, 1, 0, 1), z = rnorm(5), w = c(1, 1, 0, 1, 1) ) cb <- Codebook$new(system.file("codebook.yml", package = "codebreak")) cb$decode(ex)
label()
Label data.
Codebook$label(data, as_labelled = FALSE, .include = NULL, .exclude = NULL)
data
The data to label.
as_labelled
Should the codebook labels be applied using the labelled package?
.include
An optional character vector of column names to apply the codebook to.
.exclude
An optional character vector of column names to not apply
the codebook to. Ignored if .include
is specified.
ex <- data.frame( x = c(1, 2, 5, 3, 4), y = c(0, 1, 1, 0, 1), z = rnorm(5), w = c(1, 1, 0, 1, 1) ) cb <- Codebook$new(system.file("codebook.yml", package = "codebreak")) cb$label(ex)
print()
Codebook$print()
## ------------------------------------------------ ## Method `Codebook$new` ## ------------------------------------------------ Codebook$new(system.file("codebook.yml", package = "codebreak")) ## ------------------------------------------------ ## Method `Codebook$decode` ## ------------------------------------------------ ex <- data.frame( x = c(1, 2, 5, 3, 4), y = c(0, 1, 1, 0, 1), z = rnorm(5), w = c(1, 1, 0, 1, 1) ) cb <- Codebook$new(system.file("codebook.yml", package = "codebreak")) cb$decode(ex) ## ------------------------------------------------ ## Method `Codebook$label` ## ------------------------------------------------ ex <- data.frame( x = c(1, 2, 5, 3, 4), y = c(0, 1, 1, 0, 1), z = rnorm(5), w = c(1, 1, 0, 1, 1) ) cb <- Codebook$new(system.file("codebook.yml", package = "codebreak")) cb$label(ex)
## ------------------------------------------------ ## Method `Codebook$new` ## ------------------------------------------------ Codebook$new(system.file("codebook.yml", package = "codebreak")) ## ------------------------------------------------ ## Method `Codebook$decode` ## ------------------------------------------------ ex <- data.frame( x = c(1, 2, 5, 3, 4), y = c(0, 1, 1, 0, 1), z = rnorm(5), w = c(1, 1, 0, 1, 1) ) cb <- Codebook$new(system.file("codebook.yml", package = "codebreak")) cb$decode(ex) ## ------------------------------------------------ ## Method `Codebook$label` ## ------------------------------------------------ ex <- data.frame( x = c(1, 2, 5, 3, 4), y = c(0, 1, 1, 0, 1), z = rnorm(5), w = c(1, 1, 0, 1, 1) ) cb <- Codebook$new(system.file("codebook.yml", package = "codebreak")) cb$label(ex)