Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update by in join block (in case of empty set intersection) #274

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions R/block.R
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,11 @@
#' @param filter_fun Default filter fun for the expression.
#' @rdname new_block
#' @export
new_filter_block <- function(
data,
columns = colnames(data)[1L],
values = character(),
filter_fun = "==",
...) {
new_filter_block <- function(data, columns = colnames(data)[1L],
values = character(), filter_fun = "==", ...) {

sub_fields <- function(data, columns) {

determine_field <- function(x) {
switch(class(x),
factor = select_field,
Expand All @@ -419,6 +417,10 @@
)
}

if (!length(columns) || !all(columns %in% colnames(data))) {
return(list())

Check warning on line 421 in R/block.R

View check run for this annotation

Codecov / codecov/patch

R/block.R#L421

Added line #L421 was not covered by tests
}

cols <- data[, columns, drop = FALSE]

ctor <- lapply(cols, determine_field)
Expand All @@ -429,7 +431,9 @@


filter_exps <- function(data, values, filter_func) {

filter_exp <- function(cls, col, val) {

if (is.null(val)) {
return(quote(TRUE))
}
Expand All @@ -447,8 +451,16 @@
)
}

if (!length(values)) {
return(list())

Check warning on line 455 in R/block.R

View check run for this annotation

Codecov / codecov/patch

R/block.R#L455

Added line #L455 was not covered by tests
}

cols <- names(values)

if (!all(cols %in% colnames(data))) {
return(list())

Check warning on line 461 in R/block.R

View check run for this annotation

Codecov / codecov/patch

R/block.R#L461

Added line #L461 was not covered by tests
}

Reduce(
function(x, y) bquote(.(lhs) | .(rhs), list(lhs = x, rhs = y)),
Map(filter_exp, chr_ply(data[, cols, drop = FALSE], class), cols, values)
Expand All @@ -462,28 +474,15 @@
values = new_list_field(values, sub_fields),
filter_func = new_select_field(
filter_fun,
choices = c(
"==",
"!=",
"!startsWith",
"startsWith",
"grepl",
">",
"<",
">=",
"<="
)
choices = c("==", "!=", "!startsWith", "startsWith", "grepl", ">", "<",
">=", "<=")
),
expression = new_hidden_field(filter_exps)
)

expr <- quote(
dplyr::filter(.(expression))
)

new_block(
fields = fields,
expr = expr,
expr = quote(dplyr::filter(.(expression))),
...,
class = c("filter_block", "transform_block", "submit_block")
)
Expand Down
12 changes: 9 additions & 3 deletions R/field.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,17 @@ initialize_field.field <- function(x, env = list()) {
}

eval_set_field_value <- function(x, env) {

for (cmp in names(x)[lgl_ply(x, is.function)]) {

fun <- x[[cmp]]
tmp <- do.call(fun, env[methods::formalArgs(fun)])
if (length(tmp) > 0) {
value(x, cmp) <- tmp

res <- try(
do.call(fun, env[methods::formalArgs(fun)])
)

if (!inherits(res, "try-error")) {
value(x, cmp) <- res
}
}

Expand Down
7 changes: 3 additions & 4 deletions man/new_block.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading