@Aurele , , rlang, , , get. , get , , , . , , , .
1. /
summary do, get(..., .) , . , , get group by. , do , do , .
find_dataset_inconsistencies <- function(df, target_column, cols_to_use) {
df %>%
group_by_at(cols_to_use) %>%
do(summarise(., uTargets = length(unique(get(target_column, .))))) %>%
filter(uTargets > 1)
}
find_dataset_inconsistencies(mtcars, "mpg", c("cyl", "vs", "am", "gear", "carb"))
foo <- 3
find_dataset_inconsistencies(mtcars, "foo", c("cyl", "vs", "am", "gear", "carb"))
2. = FALSE
find_dataset_inconsistencies <- function(df, target_column, cols_to_use) {
df %>%
group_by_at(cols_to_use) %>%
summarise(uTargets = length(unique(get(target_column,
parent.env(parent.env(environment())), inherits = FALSE)))) %>%
filter(uTargets > 1)
}
find_dataset_inconsistencies(mtcars, "mpg", c("cyl", "vs", "am", "gear", "carb"))
foo <- 3
find_dataset_inconsistencies(mtcars, "foo", c("cyl", "vs", "am", "gear", "carb"))
, get :
GET <- function(x) {
p <- parent.frame()
p3 <- parent.env(parent.env(p))
get(x, p3, inherits = FALSE)
}
find_dataset_inconsistencies <- function(df, target_column, cols_to_use) {
df %>%
group_by_at(cols_to_use) %>%
summarise(uTargets = length(unique(GET(target_column)))) %>%
filter(uTargets > 1)
}
find_dataset_inconsistencies(mtcars, "mpg", c("cyl", "vs", "am", "gear", "carb"))
foo <- 3
find_dataset_inconsistencies(mtcars, "foo", c("cyl", "vs", "am", "gear", "carb"))
3.
- . mtcars , , :
library(tidyr)
find_dataset_inconsistencies <- function(df, target_column, cols_to_use) {
df %>%
rownames_to_column %>%
group_by_at(cols_to_use) %>%
summarise(uTargets = length(unique(
get(target_column, .[.$rowname %in% rowname, ])))) %>%
filter(uTargets > 1)
}
find_dataset_inconsistencies(mtcars, "mpg", c("cyl", "vs", "am", "gear", "carb"))
find_dataset_inconsistencies(mtcars, "foo", c("cyl", "vs", "am", "gear", "carb"))