Skip to contents

Compares the values between the two `data.frames` and creates a small `diff` object that stores the datetimes of the change and the new and old values. Used to move between versions. Note that this function does not currently support addition and removal of columns, but row additions/subtractions are supported.

Usage

get_diff(olddata, newdata, id = c("DateTime_rd", "DupNum"), ignore = NA)

Arguments

olddata

a `data.frame` with the original data.

newdata

a `data.frame` with the revised data.

id

name of the column name used to match observations between `olddata` and `newdata`. Must be convertible to a number.

ignore

a character vector including any column names to not track.

Value

A `diff` object with a named list item for each column being tracked. Each list item will either be `NULL` if there were no changes to that column or have the following structure: - op_type: a character describing the type of change made - id: the id values for the change made - new_data: the values of the changed values in `newdata` - old_data: the values of the changed values in `olddata`

Examples

data1 <- example_data[1:10,]
data2 <- data1
data2$fDOM_QSU[1:4] <- NA
get_diff(data1, data2)
#> $Index
#> NULL
#> 
#> $FileName
#> NULL
#> 
#> $Date
#> NULL
#> 
#> $Time_HH_mm_ss
#> NULL
#> 
#> $DateTime
#> NULL
#> 
#> $Site_Name
#> NULL
#> 
#> $Battery_V
#> NULL
#> 
#> $fDOM_QSU
#> # A tibble: 4 × 5
#>   DateTime_rd         DupNum   old   new op_type     
#>   <dttm>               <int> <dbl> <dbl> <chr>       
#> 1 2024-07-31 12:00:00      1  9.95    NA data_removed
#> 2 2024-07-31 12:15:00      1  9.87    NA data_removed
#> 3 2024-07-31 12:30:00      1  9.72    NA data_removed
#> 4 2024-07-31 12:45:00      1  9.69    NA data_removed
#> 
#> $fDOM_QSU_flag
#> NULL
#> 
#> $ODO_mg_L
#> NULL
#> 
#> $ODO_mg_L_flag
#> NULL
#> 
#> $pH
#> NULL
#> 
#> $pH_flag
#> NULL
#> 
#> $SpCond_uS_cm
#> NULL
#> 
#> $SpCond_uS_cm_flag
#> NULL
#> 
#> $Temp_C
#> NULL
#> 
#> $Temp_C_flag
#> NULL
#> 
#> $Turbidity_FNU
#> NULL
#> 
#> $Turbidity_FNU_flag
#> NULL
#> 
#> attr(,"class")
#> [1] "diff"