Kaynağa Gözat

Refactor use of quoting to get input text

Adds get_input_text() that can be used to get the literal variable name and make_named_data() that creates a list with the input data frames. This second one is necessary because the inputs may be quosures and we need to get the underlying data frames. Default names are $x and $y.
pull/18/merge
Garrick Aden-Buie 7 yıl önce
ebeveyn
işleme
5dcdf5fb91
2 değiştirilmiş dosya ile 16 ekleme ve 15 silme
  1. +5
    -15
      R/animate_joins.R
  2. +11
    -0
      R/utils.R

+ 5
- 15
R/animate_joins.R Dosyayı Görüntüle

@@ -68,19 +68,9 @@ animate_join <- function(
) {
type <- match.arg(type)
export <- match.arg(export)

if (rlang::is_quosure(x)) {
x_name <- rlang::quo_name(x)
x <- rlang::eval_tidy(x)
} else {
x_name <- rlang::quo_name(rlang::enquo(x))
}
if (rlang::is_quosure(y)) {
y_name <- rlang::quo_name(y)
y <- rlang::eval_tidy(y)
} else {
y_name <- rlang::quo_name(rlang::enquo(y))
}
x_name <- get_input_text(x)
y_name <- get_input_text(y)
data <- make_named_data(x, y)

by_args <- if (length(by) == 1) sprintf("\"%s\"", by) else
sprintf("c(\"%s\")", paste(by, collapse = "\", \""))
@@ -89,10 +79,10 @@ animate_join <- function(

if (type %in% c("semi_join", "anti_join")) {
# for semi and anti_joins, there is no adding of multiple rows
y <- dplyr::distinct(y)
data$y <- dplyr::distinct(data$y)
}

ll <- process_join(x, y, by, ...)
ll <- process_join(data$x, data$y, by, ...)

step0 <- bind_rows(ll$x, ll$y) %>% mutate(.frame = 0, .alpha = 1)


+ 11
- 0
R/utils.R Dosyayı Görüntüle

@@ -13,3 +13,14 @@ choose_text_color <- function(x, black = "#000000", white = "#FFFFFF") {
# threshold is supposed to be 0.179 but 1/3 seems to work better for our plots
ifelse(lum > 1/3, black, white)
}

get_input_text <- function(x) {
if (!rlang::is_quosure(x)) x <- rlang::enquo(x)
rlang::quo_name(x)
}

make_named_data <- function(x, y, data_names = c("x", "y")) {
ll <- rlang::eval_tidy(rlang::quo(list(!!x, !!y)))
names(ll) <- data_names
ll
}

Yükleniyor…
İptal
Kaydet