-
Notifications
You must be signed in to change notification settings - Fork 274
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
Rework simplification #909
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Errors are missing full stops.
list_simplify()
implementationConflicts: R/utils.R tests/testthat/test-utils.R
Conflicts: NAMESPACE
Co-authored-by: Lionel Henry <lionel.hry@gmail.com>
Conflicts: NEWS.md _pkgdown.yml
R/list-simplify.R
Outdated
#' @details | ||
#' Simplification maintains a one-to-one correspondence between the input | ||
#' and output, implying that each element of `x` must contain a vector of | ||
#' length 1. If you don't want to maintain this correspondence, then you | ||
#' probably want either [list_c()] or [list_flatten()]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No @description
? I feel like these details would probably make a decent description instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. No idea why I did that.
#' try(list_simplify(list(1, 2, "x"))) | ||
#' try(list_simplify(list(1, 2, 1:3))) | ||
list_simplify <- function(x, strict = TRUE, ptype = NULL) { | ||
simplify_impl(x, strict = strict, ptype = ptype) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe do some validation of strict
?
R/list-simplify.R
Outdated
error_call = caller_env() | ||
) { | ||
if (length(simplify) > 1 || !is.logical(simplify)) { | ||
cli::cli_abort("{.arg simplify} must be `TRUE`, `FALSE`, or `NA`.", arg = "simplify") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass error_call
through
R/list-simplify.R
Outdated
cli::cli_abort("{.arg simplify} must be `TRUE`, `FALSE`, or `NA`.", arg = "simplify") | ||
} | ||
if (!is.null(ptype) && isFALSE(simplify)) { | ||
cli::cli_abort("Can't specify {.arg ptype} when `simplify = FALSE`.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass error_call
through
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should arg = "ptype"
be set?
@@ -162,8 +152,8 @@ test_that("basic accumulate2() works", { | |||
paste2 <- function(x, y, sep) paste(x, y, sep = sep) | |||
|
|||
x <- c("a", "b", "c") | |||
expect_equal(accumulate2(x, c("-", "."), paste2), list("a", "a-b", "a-b.c")) | |||
expect_equal(accumulate2(x, c(".", "-", "."), paste2, .init = "x"), list("x", "x.a", "x.a-b", "x.a-b.c")) | |||
expect_equal(accumulate2(x, c("-", "."), paste2), c("a", "a-b", "a-b.c")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if the switch to auto simplification will break much code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's only one use of accumulate2()
on CRAN, so I don't think it's likely to affect much user code.
* `transpose()` has been deprecated in favour of `list_transpose()` (#875). | ||
It has built-in simplification. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think my biggest worry is that list_transpose()
is probably a lot slower than transpose()
, but I guess it is way more featureful and generic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, hopefully it's not used in too many performance critical places.
Co-authored-by: Davis Vaughan <davis@rstudio.com>
With this,
map_vec()
will become:transpose()
tolist_transpose()
#875 by introducinglist_transpose()
accumulate()
to opt out of simplification.accumulate()
andaccumulate2()
semantics.flatten()
,simplify()
and friends #900 by concluding the flatten/simplification re-alignment.