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

Properly handle cols argument of measure() #5064

Closed
wants to merge 7 commits into from
Closed
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
21 changes: 18 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,26 @@ eval_with_cols = function(orig_call, all_cols) {
})
if (!is.primitive(fun)) {
named_call = match.call(fun, orig_call)
if ("cols" %in% names(formals(fun)) && !"cols" %in% names(named_call)) {
named_call[["cols"]] = all_cols
offsets = NULL
if ("cols" %in% names(formals(fun))) {
if (!"cols" %in% names(named_call)) {
named_call[["cols"]] = all_cols
} else if (is.language(named_call[["cols"]])) {
named_call[["cols"]] = eval(named_call[["cols"]], parent)
}
if (!is.character(named_call[["cols"]]) & !all(named_call[["cols"]] %in% all_cols)) {
stop("cols must be a subset of the column names of data")
}
# not strictly needed when cols == all_cols, which is probably the most common case,
# but overhead is minimal and this simplifies control flow
offsets = which(all_cols %in% named_call[["cols"]])
}
named_call[[1L]] = fun
eval(named_call, parent)
ans = eval(named_call, parent)
if (as.character(fun_uneval) %in% c('measure', 'measurev') & is.integer(ans)) { # the original measure/v
ans = setattr(offsets[ans], "variable_table", attributes(ans)[["variable_table"]])
}
return(ans)
}
}

Expand Down