-
Notifications
You must be signed in to change notification settings - Fork 2.1k
cur_data() / cur_data_all() not simplifying list columns
#6020
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
Changes from 2 commits
53ae33d
339d581
23c6a95
dba55ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -67,6 +67,14 @@ DataMask <- R6Class("DataMask", | |||
|
|
||||
| pick = function(vars) { | ||||
| cols <- self$current_cols(vars) | ||||
| if (inherits(private$data, "rowwise_df")) { | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain why we have to re-wrap in a list? (As opposed to not unwrapping somewhere?)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It happens in this line: Line 20 in bb84360
void dplyr_lazy_vec_chop_grouped(SEXP chops_env, SEXP rows, SEXP data, bool rowwise) {
SEXP names = PROTECT(Rf_getAttrib(data, R_NamesSymbol));
R_xlen_t n = XLENGTH(data);
const SEXP* p_data = VECTOR_PTR_RO(data);
const SEXP* p_names = STRING_PTR_RO(names);
for (R_xlen_t i = 0; i < n; i++) {
SEXP prom = PROTECT(Rf_allocSExp(PROMSXP));
SET_PRENV(prom, R_EmptyEnv);
SEXP column = p_data[i];
if (rowwise && vctrs::vec_is_list(column) && Rf_length(column) > 0) {
SET_PRCODE(prom, column);
} else {
SET_PRCODE(prom, Rf_lang3(dplyr::functions::vec_chop, column, rows));
}
SET_PRVALUE(prom, R_UnboundValue);
Rf_defineVar(rlang::str_as_symbol(p_names[i]), prom, chops_env);
UNPROTECT(1);
}
UNPROTECT(1);
}When we setup the promise that makes the chops, and this is a rowwise data, we can skip using This gives us the rowwise simplification for when we refer to the list column in an expression (not having to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... and for non-original columns, i.e. those that are added, they go through the add_one = function(name, chunks, result) {
if (inherits(private$data, "rowwise_df")){
is_scalar_list <- function(.x) {
vec_is_list(.x) && length(.x) == 1L
}
if (all(map_lgl(chunks, is_scalar_list))) {
chunks <- map(chunks, `[[`, 1L)
}
}
.Call(`dplyr_mask_add`, private, name, result, chunks)
},
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah makes sense. Thanks! |
||||
| cols <- map2(cols, names(cols), function(col, name) { | ||||
| if (vec_is_list(private$current_data[[name]])) { | ||||
| col <- list(col) | ||||
| } | ||||
| col | ||||
| }) | ||||
| } | ||||
| nrow <- length(self$current_rows()) | ||||
| new_tibble(cols, nrow = nrow) | ||||
| }, | ||||
|
|
||||
Uh oh!
There was an error while loading. Please reload this page.