-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.Rmd
More file actions
81 lines (61 loc) · 2.92 KB
/
Copy pathREADME.Rmd
File metadata and controls
81 lines (61 loc) · 2.92 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# controller
<!-- badges: start -->
[](https://www.repostatus.org/#active)
[](https://CRAN.R-project.org/package=controller)
[](https://github.com/joeroe/controller/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/joeroe/controller)
[](https://doi.org/10.5281/zenodo.21515711)
[](https://cranlogs.r-pkg.org/)
<!-- badges: end -->
**controller** is a collection of functions for working with controlled vocabularies in R.
It introduces the `control()` verb, which recodes values in a vector using a lookup table of preferred and variant terms (a *thesaurus*).
## Installation
You can install the latest release of controller [from CRAN](https://cran.r-project.org/package=controller) with:
```{r install, eval=FALSE}
install.packages("controller")
```
Or the development version from GitHub using the [remotes](https://remotes.r-lib.org/) package:
```{r install-dev, eval=FALSE}
# install.packages("remotes")
remotes::install_github("joeroe/controller")
```
## Usage
A common data-tidying problem is standardising variant terms for the same concept.
Imagine we have a dataset that uses a number of different names for shades of the same colour.
As data analysts, we naturally want to recode the data to eliminate this messy creativity, for example using [dplyr::recode()](https://dplyr.tidyverse.org/reference/recode.html):
```{r eg-dplyr}
library(dplyr, warn.conflicts = FALSE)
shades <- c("daffodil", "purple", "magenta", "azure", "navy", "violet")
recode(shades,
daffodil = "yellow",
purple = "purple",
magenta = "pink",
azure = "blue",
navy = "blue",
violet = "purple")
```
But recoding this way can be tedious, especially if there are a large number of terms.
With `control()`, we can instead use a data frame containing a thesaurus to replace the values:
```{r eg-controller}
library(controller)
data("colour_thesaurus")
control(shades, colour_thesaurus)
```
`control()` also supports fuzzy matching, removing the need to exhaustively list variants for common causes of differing terminology.
For example, to perform a case insensitive match to the thesaurus:
```{r eg-ci}
shades <- toupper(shades)
control_ci(shades, colour_thesaurus)
```