| Title: | Inspect Data Pipelines |
|---|---|
| Description: | Inspect data pipelines (especially magrittr pipelines) for before-after changes during tricky operations. |
| Authors: | Brian Vancil [aut, cre] (ORCID: <https://orcid.org/0000-0003-1145-3681>) |
| Maintainer: | Brian Vancil <[email protected]> |
| License: | GPL (>= 3) + file LICENSE |
| Version: | 0.0.0.9000 |
| Built: | 2026-06-03 07:41:16 UTC |
| Source: | https://github.com/bvancil/multimeter |
Counter R6 class to represent a counter
Counter R6 class to represent a counter
countnumber of times that something has happened
new()
Create a new Counter object.
Counter$new()
A new Counter object.
print()
Print a Counter object.
Counter$print(...)
...required for compatibility with print()
self
increment()
Add one to counter.
Counter$increment()
NULL
chain_increment()
Add one to counter.
Counter$chain_increment()
self
pipe_increment()
Add one to counter.
Counter$pipe_increment(.data)
.datapiped dataset
.data
reset()
Reset counter to zero.
Counter$reset()
self
clone()
The objects of this class are cloneable with this method.
Counter$clone(deep = FALSE)
deepWhether to make a deep clone.
History R6 class to represent historical values
History R6 class to represent historical values
valueslist of stored values
new()
Create a new History object.
History$new()
A new History object.
print()
Print summary of Counter object
History$print(...)
...unused
log()
Store a value
History$log(val)
valvalue to add to history
NULL
chain_log()
Store a value
History$chain_log(val)
valvalue to add to history
self
pipe_log()
Store a value
History$pipe_log(val)
valvalue to add to history
val
reset()
Clear history
History$reset(x)
xpipeline value passed in (Optional)
clone()
The objects of this class are cloneable with this method.
History$clone(deep = FALSE)
deepWhether to make a deep clone.
Simple meter that does not transform its input and performs no comparison of results other than returning them.
mm_get_identity_meter()mm_get_identity_meter()
Multimeter instance
if (interactive()) { m <- mm_get_identity_meter() m$probe(1L) == 1L m$probe(2L) == 2L m$comparison print(m) }if (interactive()) { m <- mm_get_identity_meter() m$probe(1L) == 1L m$probe(2L) == 2L m$comparison print(m) }
This is useful after mutate operations but may give
false positives after a summarize.
mm_get_missing_meter()mm_get_missing_meter()
a new Multimeter tuned to look for missing values
if (interactive()) { # Function to randomly create NAs in a variable maybe_na <- function(x, prob = 0.2) { n <- base::length(x) missing_of_type_x <- vctrs::vec_cast(NA, to = vctrs::vec_ptype(x)) dplyr::if_else(stats::runif(n) < prob, missing_of_type_x, x) } # In pieces, to see what's going on missing_meter <- mm_get_missingness_meter() library(dplyr) missing_meter$probe(starwars) set.seed(2021L + 06L + 28L) starwars2 <- starwars %>% mutate(homeworld = maybe_na(homeworld)) missing_meter$probe(starwars2) print(missing_meter$comparison) # All together in one pipeline starwars2 <- starwars %>% missing_meter$reset() %>% missing_meter$probe() %>% mutate(homeworld = maybe_na(homeworld)) %>% missing_meter$probe() print(missing_meter$comparison) }if (interactive()) { # Function to randomly create NAs in a variable maybe_na <- function(x, prob = 0.2) { n <- base::length(x) missing_of_type_x <- vctrs::vec_cast(NA, to = vctrs::vec_ptype(x)) dplyr::if_else(stats::runif(n) < prob, missing_of_type_x, x) } # In pieces, to see what's going on missing_meter <- mm_get_missingness_meter() library(dplyr) missing_meter$probe(starwars) set.seed(2021L + 06L + 28L) starwars2 <- starwars %>% mutate(homeworld = maybe_na(homeworld)) missing_meter$probe(starwars2) print(missing_meter$comparison) # All together in one pipeline starwars2 <- starwars %>% missing_meter$reset() %>% missing_meter$probe() %>% mutate(homeworld = maybe_na(homeworld)) %>% missing_meter$probe() print(missing_meter$comparison) }
Track column names before and after a transformation
mm_get_names_meter()mm_get_names_meter()
Multimeter instance
if (interactive()) { m <- mm_get_names_meter() library(dplyr) mtcars2 <- mtcars %>% m$probe() %>% mutate(square_error_from_five = (cyl - 5)^2) %>% m$probe() print(m$comparison) }if (interactive()) { m <- mm_get_names_meter() library(dplyr) mtcars2 <- mtcars %>% m$probe() %>% mutate(square_error_from_five = (cyl - 5)^2) %>% m$probe() print(m$comparison) }
Track changes in columns provided to $probe() function
mm_get_value_meter()mm_get_value_meter()
Multimeter instance
if (interactive()) { m <- mm_get_state_capture_meter() library(dplyr) mtcars2 <- mtcars %>% m$probe(cyl) %>% mutate(square_error_from_five = (cyl - 5)^2) %>% m$probe(square_error_from_five) print(m$comparison) }if (interactive()) { m <- mm_get_state_capture_meter() library(dplyr) mtcars2 <- mtcars %>% m$probe(cyl) %>% mutate(square_error_from_five = (cyl - 5)^2) %>% m$probe(square_error_from_five) print(m$comparison) }
Multimeter R6 class to represent a multimeter type
Multimeter R6 class to represent a multimeter type
A new Multimeter can insert probes in various stages
of a data pipeline, allowing you to compare output
before and after a change. To facilitate use with large
datasets for which you might only wish to store a summary
of the data, a Multimeter object can take a transform
function that transforms the data before storing it, and
a compare function to point out salient differences.
transformfunction of dataset
comparefunction of before and after transformed datasets
beforetransformed "before" dataset
aftertransformed "after" dataset
comparisonresult of compare on before
and after
new()
Create a new Multimeter object.
Multimeter$new(transformer, comparator)
transformerfunction of dataset to store
comparatorfunction of transformed dataset to compare
A new Multimeter object.
print()
Print summary of Multimeter object
Multimeter$print(...)
...unused
probe()
Insert a probe at this stage of data pipeline.
Because this operation returns the first argument, it may be used in magrittr or base R pipelines.
Multimeter$probe(.data, ..., .print_comparison = TRUE)
.datadataset tibble or data.frame
...other arguments passed on to
self$transform
.print_comparisonlogical whether to print a
comparison on the second probe. Ignored otherwise.
Default: TRUE
.data
save_memory()
Delete intermediate stored transformed before/after datasets to save memory.
Multimeter$save_memory(.data)
.datadataset Optional if used in a data pipeline
.data (or NULL if .data is missing)
reset()
Reset multimeter for repeated use
Multimeter$reset(.data)
.datadataset Optional if used in a data pipeline
.data (or NULL if .data is missing)
clone()
The objects of this class are cloneable with this method.
Multimeter$clone(deep = FALSE)
deepWhether to make a deep clone.