-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
102 lines (74 loc) · 2.76 KB
/
README.Rmd
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
---
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%"
)
```
# dcmodifydt
<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/dcmodifydt)](https://CRAN.R-project.org/package=dcmodifydt)
[![R-CMD-check](https://github.com/data-cleaning/dcmodifydt/workflows/R-CMD-check/badge.svg)](https://github.com/data-cleaning/dcmodifydt/actions)
[![Codecov test coverage](https://codecov.io/gh/data-cleaning/dcmodifydt/branch/main/graph/badge.svg)](https://codecov.io/gh/data-cleaning/dcmodifydt?branch=main)
<!-- badges: end -->
`dcmodifydt` executes [`dcmodify`](https://CRAN.R-project.org/package=dcmodify) modification rules on a data.table, making it easy to switch between data.frame
, database or data.table implementation.
`dcmodify` separates **intent** from **execution**: a user specifies _what_, _why_ and _how_ of an automatic data change and uses dcmodify to execute them on a `data.table`.
### Rationale
`data.table` is an excellent package with great performance. Why not code
modification rules directly in R script? _Keep it simple_ is certainly
a good advise, reasons to use `dcmodify` are:
- You have a set "correction" rules in a production process that you apply repeatly, e.g. in each production run.
- You want to share these rules with different production processes.
- You have data matter specialists that do not know (or have to) program in R,
and use this as a quality frame work to communicate and specify the step to
correct or derive variables.
In these cases it is useful to label, describe and document your rules, and
use `dcmodify`, `dcmodifydt` or `dcmodifydb` to apply the modification rules.
## Installation
The development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("data-cleaning/dcmodifydt")
```
## Example
```{r}
library(dcmodifydt)
```
```{r, code = readLines("example/modify.R")}
```
### Documented modification rules:
Create a modifier object:
```{r}
m <- modifier(.file = "example/example.yml")
```
From this specification file "example/example.yml":
```yml
```{r, child="example/example.yml", results="asis"}
```
```
```{r}
dat <- data.table::fread(text =
"age, income
11, 2000
150, 300
25, 2000
-10, 2000")
modify(dat, m, copy=FALSE)
print(dat)
```
For convenience it is possible to dump the data.table statements. This
file can be sourced, resulting in the modifications of the supplied table (name)
```{r, eval = FALSE}
dump_dt(m, name = "my_dt", file="change_my_dt.R")
```
```r
```{r, echo = FALSE, results="asis"}
dump_dt(m, name = "my_dt")
```
```