View source: R/data-frame-stack-new.R
data_frame_stack_new | R Documentation |
These functions help to compare two metadata frames and assess if new rows should be added.
data_frame_stack_new(
d_original,
d_current,
keys,
datestamp_update = FALSE,
datestamp_value = Sys.Date(),
stat_columns = character(0)
)
metadata_update_file(
path,
d_current,
keys,
datestamp_update = FALSE,
datestamp_value = Sys.Date(),
stat_columns = character(0)
)
d_original |
A |
d_current |
A |
keys |
Column names that represent unique combination.
|
datestamp_update |
A |
datestamp_value |
A |
stat_columns |
The name(s) of columns containing values to update.
These values in |
path |
Location of the metadata file to potentially updated.
Required |
A tibble::tibble
that combines d_original
with the new records
from d_current
.
Each dataset is verified to not have more then one
row with the same values in the combination of keys
The stat_columns
typically contain metrics like 'count' or 'mean'
which may become obsolete in d_original
. These values are dropped
from d_original
and replaced by the columns in d_current
, after
joining on the keys
column(s).
Will Beasley
data_frame_compare_structure()
library("magrittr")
ds_original <- tibble::tibble(
x1 = c(1, 3, 4),
x2 = letters[c(1, 3, 4)],
x3 = c(11, 13, 14),
x4 = c(111, 113, 114),
x5 = c(-11, -13, -14),
datestamp = as.Date("2020-01-07")
)
ds_current <- tibble::tibble(
x1 = c(1:5, 1, 5),
x2 = c(letters[1:5], "x", "y"),
x3 = c(11, 12, 13, 14, 15, 11, 15),
x4 = c(211, 212, 213, 214, 215, 211, 215),
x5 = c(311, 312, 313, 314, 315, 311, 315),
datestamp = as.Date(NA)
)
# Basic: append the new records.
data_frame_stack_new(
d_original = ds_original,
d_current = ds_current,
keys = c("x1", "x2")
)
# Wrinkle 1: datestamp the new records.
data_frame_stack_new(
d_original = ds_original,
d_current = ds_current,
keys = c("x1", "x2"),
datestamp_update = TRUE
)
# Wrinkle 2a: datestamp the new records; update x4.
data_frame_stack_new(
d_original = ds_original,
d_current = ds_current,
keys = c("x1", "x2"),
datestamp_update = TRUE,
stat_columns = c("x4")
)
# Wrinkle 2b: datestamp the new records; update x4 & x5.
data_frame_stack_new(
d_original = ds_original,
d_current = ds_current,
keys = c("x1", "x2"),
datestamp_update = TRUE,
stat_columns = c("x4", "x5")
)
ds_current %>%
dplyr::anti_join(ds_original, by = c("x1", "x2"))
# Update a file
## Not run:
{
path_temp <- tempfile(fileext = ".csv")
on.exit(unlink(path_temp))
file.copy(
system.file("test-data/metadata-original.csv", package = "OuhscMunge"),
path_temp
)
}
# Displays 3 rows.
readr::read_csv(path_temp)
metadata_update_file(
path_temp,
dplyr::mutate(ds_current, x1 = as.character(x1), x3 = as.character(x3)),
c("x1", "x2")
)
# Displays 7 rows.
readr::read_csv(path_temp)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.