diff --git a/DESCRIPTION b/DESCRIPTION index 189ccd48d..a42e27d9a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: collapse Title: Advanced and Fast Data Transformation -Version: 2.0.17.9000 -Date: 2024-11-19 +Version: 2.0.18 +Date: 2024-11-23 Authors@R: c( person("Sebastian", "Krantz", role = c("aut", "cre"), email = "sebastian.krantz@graduateinstitute.ch", diff --git a/NEWS.md b/NEWS.md index 5cfdc2a5d..032c733f2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,9 +1,11 @@ -# collapse 2.0.17.9000 +# collapse 2.0.18 * Cases in `pivot(..., how = "longer")` with no `values` columns now no longer give an error. Thanks @alvarocombo for flagging this (#663). * Fixed bug in `qF(c(4L, 1L, NA), sort = FALSE)`: hash function failure due to a coding bug. Thanks @mayer79 for flagging this (#666). +* If `x` is already a `qG` object of the right properties, calling `qG(x)` now does not copy `x` anymore. Thanks @mayer79 (https://github.com/mayer79/effectplots/issues/11). + # collapse 2.0.17 * In `GRP.default()`, the `"group.starts"` attribute is always returned, even if there is only one group or every observation is its own group. Thanks @JamesThompsonC (#631). diff --git a/R/GRP.R b/R/GRP.R index c386ad000..18a686390 100644 --- a/R/GRP.R +++ b/R/GRP.R @@ -732,6 +732,7 @@ qG <- function(x, ordered = FALSE, na.exclude = TRUE, sort = .op[["sort"]], ax <- if(return.groups) list(N.groups = attr(x, "N.groups"), groups = attr(x, "groups"), class = newclx) else list(N.groups = attr(x, "N.groups"), class = newclx) } + if(identical(ax, attributes(x))) return(x) return(`attributes<-`(x, ax)) } newclx <- c(if(ordered) "ordered", "qG", "na.included") diff --git a/src/data.table_subset.c b/src/data.table_subset.c index 02be2c3e5..d5d85ff0c 100644 --- a/src/data.table_subset.c +++ b/src/data.table_subset.c @@ -82,7 +82,9 @@ static SEXP shallow(SEXP dt, SEXP cols, R_len_t n) SEXP newdt = PROTECT(allocVector(VECSXP, n)); protecti++; // to do, use growVector here? SET_ATTRIB(newdt, shallow_duplicate(ATTRIB(dt))); SET_OBJECT(newdt, OBJECT(dt)); - if(IS_S4_OBJECT(dt)) newdt = asS4(newdt, TRUE, 1); // To support S4 objects that include data.table + if(IS_S4_OBJECT(dt)) { + newdt = PROTECT(asS4(newdt, TRUE, 1)); protecti++; // To support S4 objects that include data.table + } //SHALLOW_DUPLICATE_ATTRIB(newdt, dt); // SHALLOW_DUPLICATE_ATTRIB would be a bit neater but is only available from R 3.3.0 // TO DO: keepattr() would be faster, but can't because shallow isn't merely a shallow copy. It