Package 'codebreak'

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

Help Index


R6 Class representing a codebook

Description

Decode and label data using a codebook saved as a YAML text file.

Public fields

path

Path to a YAML text file.

codebook

The codebook.

Methods

Public methods


Method new()

Import a YAML codebook

Usage
Codebook$new(path = "codebook.yml")
Arguments
path

The path to the YAML codebook.

Returns

A new 'Codebook' object.

Examples
Codebook$new(system.file("codebook.yml", package = "codebreak"))

Method decode()

Decode data.

Usage
Codebook$decode(
  data,
  label = FALSE,
  as_labelled = FALSE,
  .include = NULL,
  .exclude = NULL
)
Arguments
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.

Returns

An updated copy of data.

Examples
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 label()

Label data.

Usage
Codebook$label(data, as_labelled = FALSE, .include = NULL, .exclude = NULL)
Arguments
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.

Examples
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 print()

Usage
Codebook$print()

Examples

## ------------------------------------------------
## 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)