this makes it easier to differentiate between the join-related and the (coming) tidyr-related functions that have similar goalspull/10/head
| } | } | ||||
| if (type == "union_all") { | if (type == "union_all") { | ||||
| ll <- preprocess_data(x, y, by = names(x), fill = FALSE, ...) | |||||
| ll <- process_join(x, y, by = names(x), fill = FALSE, ...) | |||||
| ll <- lapply(ll, function(a) | ll <- lapply(ll, function(a) | ||||
| a %>% mutate(.id_long = paste(.id_long, .side, sep = "-")) | a %>% mutate(.id_long = paste(.id_long, .side, sep = "-")) | ||||
| ) | ) | ||||
| } else { | } else { | ||||
| ll <- preprocess_data(x, y, by = names(x), ...) | |||||
| ll <- process_join(x, y, by = names(x), ...) | |||||
| } | } | ||||
| step0 <- bind_rows(ll$x, ll$y) %>% mutate(.frame = 0, .alpha = 1) | step0 <- bind_rows(ll$x, ll$y) %>% mutate(.frame = 0, .alpha = 1) | ||||
| y <- dplyr::distinct(y) | y <- dplyr::distinct(y) | ||||
| } | } | ||||
| ll <- preprocess_data(x, y, by, ...) | |||||
| ll <- process_join(x, y, by, ...) | |||||
| step0 <- bind_rows(ll$x, ll$y) %>% mutate(.frame = 0, .alpha = 1) | step0 <- bind_rows(ll$x, ll$y) %>% mutate(.frame = 0, .alpha = 1) | ||||
| #' | #' | ||||
| #' @examples | #' @examples | ||||
| #' NULL | #' NULL | ||||
| preprocess_data <- function(x, y, by, fill = TRUE, ...) { | |||||
| process_join <- function(x, y, by, fill = TRUE, ...) { | |||||
| #' test for | #' test for | ||||
| #' a <- c("unique", "mult", "mult", "also unique") | #' a <- c("unique", "mult", "mult", "also unique") | ||||
| ids <- dplyr::union(x %>% dplyr::select(.id, .id_long), | ids <- dplyr::union(x %>% dplyr::select(.id, .id_long), | ||||
| y %>% dplyr::select(.id, .id_long)) | y %>% dplyr::select(.id, .id_long)) | ||||
| x_ <- process_data(x, ids, by, fill = fill, ...) | |||||
| y_ <- process_data(y, ids, by, fill = fill, ...) %>% | |||||
| x_ <- process_data_join(x, ids, by, fill = fill, ...) | |||||
| y_ <- process_data_join(y, ids, by, fill = fill, ...) %>% | |||||
| mutate(.x = .x + ncol(x) - 1) | mutate(.x = .x + ncol(x) - 1) | ||||
| return(list(x = x_, y = y_)) | return(list(x = x_, y = y_)) | ||||
| #' | #' | ||||
| #' @examples | #' @examples | ||||
| #' NULL | #' NULL | ||||
| process_data <- function(x, ids, by, width = 1, side = NA, fill = TRUE, ...) { | |||||
| process_data_join <- function(x, ids, by, width = 1, side = NA, fill = TRUE, ...) { | |||||
| if (is.na(side)) side <- deparse(substitute(x)) | if (is.na(side)) side <- deparse(substitute(x)) | ||||
| x_names <- names(x) %>% str_subset("^[^\\.]") | x_names <- names(x) %>% str_subset("^[^\\.]") | ||||
| } | } | ||||
| } | } | ||||
| res <- add_color(x, rev(ids$.id), by, ...) | |||||
| res <- add_color_join(x, rev(ids$.id), by, ...) | |||||
| return(res) | return(res) | ||||
| } | } | ||||
| #' | #' | ||||
| #' @examples | #' @examples | ||||
| #' NULL | #' NULL | ||||
| add_color <- function(x, ids, by, | |||||
| add_color_join <- function(x, ids, by, | |||||
| color_header = "#737373", color_other = "#d0d0d0", | color_header = "#737373", color_other = "#d0d0d0", | ||||
| color_missing = "#ffffff", | color_missing = "#ffffff", | ||||
| color_fun = scales::brewer_pal(type = "qual", "Set1"), | color_fun = scales::brewer_pal(type = "qual", "Set1"), |
| % Generated by roxygen2: do not edit by hand | % Generated by roxygen2: do not edit by hand | ||||
| % Please edit documentation in R/process_data_helpers.R | % Please edit documentation in R/process_data_helpers.R | ||||
| \name{add_color} | |||||
| \alias{add_color} | |||||
| \name{add_color_join} | |||||
| \alias{add_color_join} | |||||
| \title{Adds Color to a processed data_frame} | \title{Adds Color to a processed data_frame} | ||||
| \usage{ | \usage{ | ||||
| add_color(x, ids, by, color_header = "#737373", | |||||
| add_color_join(x, ids, by, color_header = "#737373", | |||||
| color_other = "#d0d0d0", color_missing = "#ffffff", | color_other = "#d0d0d0", color_missing = "#ffffff", | ||||
| color_fun = scales::brewer_pal(type = "qual", "Set1"), | color_fun = scales::brewer_pal(type = "qual", "Set1"), | ||||
| text_color = NA, ...) | text_color = NA, ...) |
| % Generated by roxygen2: do not edit by hand | % Generated by roxygen2: do not edit by hand | ||||
| % Please edit documentation in R/process_data_helpers.R | % Please edit documentation in R/process_data_helpers.R | ||||
| \name{process_data} | |||||
| \alias{process_data} | |||||
| \name{process_data_join} | |||||
| \alias{process_data_join} | |||||
| \title{Processes the data} | \title{Processes the data} | ||||
| \usage{ | \usage{ | ||||
| process_data(x, ids, by, width = 1, side = NA, fill = TRUE, ...) | |||||
| process_data_join(x, ids, by, width = 1, side = NA, fill = TRUE, ...) | |||||
| } | } | ||||
| \arguments{ | \arguments{ | ||||
| \item{x}{a preprocessed dataset} | \item{x}{a preprocessed dataset} |
| % Generated by roxygen2: do not edit by hand | % Generated by roxygen2: do not edit by hand | ||||
| % Please edit documentation in R/process_data_helpers.R | % Please edit documentation in R/process_data_helpers.R | ||||
| \name{preprocess_data} | |||||
| \alias{preprocess_data} | |||||
| \name{process_join} | |||||
| \alias{process_join} | |||||
| \title{Preprocess data} | \title{Preprocess data} | ||||
| \usage{ | \usage{ | ||||
| preprocess_data(x, y, by, fill = TRUE, ...) | |||||
| process_join(x, y, by, fill = TRUE, ...) | |||||
| } | } | ||||
| \arguments{ | \arguments{ | ||||
| \item{x}{a left dataset} | \item{x}{a left dataset} |