Create modified data
create_modified_data.RdCreate modified data
Usage
create_modified_data(
compare,
base,
by = NULL,
by_col = NULL,
cols = NULL,
ignore_case = FALSE,
trim_ws = FALSE
)Arguments
- compare
A 'current' or 'new' dataset (tibble or data.frame)
- base
A 'previous' or 'old' dataset (tibble or data.frame)
- by
A join column between the two datasets, or any combination of columns that constitute a unique row.
- by_col
A new name for the joining column.
- cols
Columns to be compared.
- ignore_case, trim_ws
passed to
compare_values()for character comparisons.
Value
a list with diffs (long format: Variable name, key column(s),
Current Value, Previous Value), diffs_byvar (count of differing
values per variable), and class_diffs (class mismatches by shared
column)
Examples
# with local data
CurrentData <- dfdiffs::ChangedData
PreviousData <- dfdiffs::InitialData
create_modified_data(
compare = CurrentData,
base = PreviousData,
by = c("subject_id", "record"),
cols = c("text_value_a", "text_value_b", "updated_date"))
#> $diffs
#> # A tibble: 8 × 4
#> `Variable name` join `Current Value` `Previous Value`
#> <chr> <chr> <chr> <chr>
#> 1 text_value_a A-1 Issue resolved Issue unresolved
#> 2 text_value_a A-2 Issue resolved Issue unresolved
#> 3 text_value_b C-4 Joint pain, stiffness and swelling Joint pain
#> 4 updated_date A-1 2021-10-03 2021-09-29
#> 5 updated_date A-2 2021-11-27 2021-10-03
#> 6 updated_date B-3 2021-10-20 2021-09-02
#> 7 updated_date C-4 2021-10-13 2021-10-03
#> 8 updated_date C-5 2021-10-14 2021-09-20
#>
#> $diffs_byvar
#> # A tibble: 3 × 2
#> `Variable name` `Modified Values`
#> <chr> <int>
#> 1 text_value_a 2
#> 2 text_value_b 1
#> 3 updated_date 5
#>
#> $class_diffs
#> # A tibble: 0 × 3
#> # ℹ 3 variables: variable <chr>, class_base <chr>, class_compare <chr>
#>
create_modified_data(
compare = CurrentData,
base = PreviousData,
by = c("subject_id", "record"))
#> $diffs
#> # A tibble: 13 × 4
#> `Variable name` join `Current Value` `Previous Value`
#> <chr> <chr> <chr> <chr>
#> 1 text_value_a A-1 Issue resolved Issue unresolved
#> 2 text_value_a A-2 Issue resolved Issue unresolved
#> 3 text_value_b C-4 Joint pain, stiffness and swelling Joint pain
#> 4 updated_date A-1 2021-10-03 2021-09-29
#> 5 updated_date A-2 2021-11-27 2021-10-03
#> 6 updated_date B-3 2021-10-20 2021-09-02
#> 7 updated_date C-4 2021-10-13 2021-10-03
#> 8 updated_date C-5 2021-10-14 2021-09-20
#> 9 entered_date A-1 2021-11-30 2021-09-29
#> 10 entered_date A-2 2021-11-30 2021-10-29
#> 11 entered_date B-3 2021-11-21 2021-08-18
#> 12 entered_date C-4 2021-11-11 2021-10-03
#> 13 entered_date C-5 2021-11-16 2021-10-20
#>
#> $diffs_byvar
#> # A tibble: 7 × 2
#> `Variable name` `Modified Values`
#> <chr> <int>
#> 1 subject_id 0
#> 2 record 0
#> 3 text_value_a 2
#> 4 text_value_b 1
#> 5 created_date 0
#> 6 updated_date 5
#> 7 entered_date 5
#>
#> $class_diffs
#> # A tibble: 0 × 3
#> # ℹ 3 variables: variable <chr>, class_base <chr>, class_compare <chr>
#>