knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

library(tidyverse)
library(definer)

definer

The goal of definer is to make it easy to apply field maps / survey data definitions to datasets with integer coding.

Installation

You can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("davisadamw/definer")

Example

A very basic example of what this does:

# create a definitions dataset linking coded values of various variables to what they represent
def_list <- tibble(variable   = c("A", "A", "B", "B", "C"),
                   value      = c(1,   2,   1,   2,   1),
                   definition = c("cat", "dog", "fred", "george", "lonely")) %>%
  def_prep(variable, value, definition, drop_solos = FALSE)

# make a little source dataset to run this on
source_data <- tibble(ID = c("A1", "A2", "A3"),
                      A  = c(1, 1, 2),
                      B  = c(2, 1, 2),
                      C  = c(1, 1, 1))

# run the mass recoding
updated_values <- def_recode_all(source_data, def_list)

# display the results side-by-side
left_join(source_data, updated_values, 
          by = "ID", suffix = c("_old", "_new"))

ToDos

There are three updates / improvements I have in mind before I'm ready to call this the 0.0.1 version:

One longer-term one that would require a bit more input:



davisadamw/definer documentation built on March 11, 2020, 4:14 a.m.