From 4db6fc811e6b8c27afe56ddc4419d715636199a8 Mon Sep 17 00:00:00 2001 From: Enrico Schumann Date: Fri, 29 Dec 2023 11:37:22 +0100 Subject: [PATCH] Remove 'ddf' Move function to separate package 'ddf'. --- ChangeLog | 5 +++ R/functions.R | 84 --------------------------------------------------- 2 files changed, 5 insertions(+), 84 deletions(-) diff --git a/ChangeLog b/ChangeLog index 92d63f6..909274f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2023-12-29 Enrico Schumann + + * R/functions.R (ddf): remove 'ddf', and move to + separate package 'ddf' + 2023-12-20 Enrico Schumann * R/functions.R (ddf): add arguments "ignore.columns" diff --git a/R/functions.R b/R/functions.R index 7ab1b77..f2af2ee 100644 --- a/R/functions.R +++ b/R/functions.R @@ -864,87 +864,3 @@ cache_object <- function(object, filename, path, binary = TRUE, } -ddf <- -function(new, old = NULL, - by = NULL, - ignore.case = FALSE, - ignore.ws = FALSE, - ignore.headers = FALSE, - ignore = NULL, - ignore.rows = NULL, - ignore.columns = NULL, - only.columns = NULL, - ... ) { - - - if (!ignore.headers && - length(colnames(old)) == length(colnames(new)) && - all( sort(colnames(old)) == sort(colnames(new)))) { - - if (!all(colnames(old) == colnames(new))) { - if (verbose) - message("orders of columns differ") - old <- old[, colnames(new)] - } - } - - - key.old <- if (is.character(by)) - do.call(paste, old[, by, drop = FALSE]) - else if (identical(by, 0)) - row.names(old) - else - do.call(paste, old) - - key.new <- if (is.character(by)) - do.call(paste, new[, by, drop = FALSE]) - else if (identical(by, 0)) - row.names(new) - else - do.call(paste, new) - - ## check for changes - - m <- match(key.new, key.old, nomatch = 0L) - - new. <- new[m > 0, ] - old. <- old[m, ] - key.new. <- key.new[m > 0] - - - ch.cols <- only.columns - - if (is.null(only.columns)) - ch.cols <- setdiff(colnames(new.), ignore.columns) - digest.new <- apply(new.[, ch.cols, drop = FALSE], - 1, - function(x) paste(x, collapse = "--")) - - if (is.null(only.columns)) - ch.cols <- setdiff(colnames(old.), ignore.columns) - digest.old <- apply(old.[, ch.cols, drop = FALSE], - 1, - function(x) paste(x, collapse = "--")) - - changes <- which(digest.new != digest.old) - - ans.changes <- list() - for (ch in changes) { - same <- (is.na(new.[ch, ch.cols]) & is.na(old.[ch, ch.cols])) | - new.[ch, ch.cols] == old.[ch, ch.cols] - ch.col <- setdiff(ch.cols[!same], ignore.columns) - o.n <- cbind(old = t(old.[ch, ch.col]), - new = t(new.[ch, ch.col])) - row.names(o.n) <- ch.col - colnames (o.n) <- c("old", "new") - ans.changes[[as.character(key.new.[ch])]] <- o.n - } - - ans <- list( - added = new[!key.new %in% key.old, ], - removed = old[!key.old %in% key.new, ], - changed = ans.changes) - attr(ans, "new.key") <- key.new - attr(ans, "old.key") <- key.old - ans -} -- 2.45.2