-
Notifications
You must be signed in to change notification settings - Fork 276
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
Standardise list_modify() #918
Conversation
* `NULL` now sets value * Don't recurse into non-lists Fixes #810
} | ||
#' @export | ||
#' @rdname list_modify | ||
list_merge <- function(.x, ...) { | ||
list_recurse(.x, list2(...), c) | ||
y <- dots_list(..., .named = NULL, .homonyms = "error") | ||
list_recurse(.x, y, 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.
Should we try switching to vec_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.
Yeah, that's a good idea.
x[[i]] <- NULL | ||
} else if (vec_is_list(x_i) && vec_is_list(y_i)) { | ||
list_slice2(x, i) <- list_recurse(x_i, y_i, base_f) | ||
} else { |
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 one thing that has always bothered me in these functions is this very flexible base case, i.e. that it accepts mismatches between lists and atoms. Should we require that the list structure of the lhs and rhs match, and fail otherwise?
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, that's a good idea. I'll explore.
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 this is ok — it lets you override vectors with lists and vice versa:
library(purrr)
str(list_modify(list(x = list(1, 2)), x = 2))
#> List of 1
#> $ x: num 2
str(list_modify(list(x = 2), x = list(1, 2)))
#> List of 1
#> $ x:List of 2
#> ..$ : num 1
#> ..$ : num 2
Created on 2022-09-07 with reprex v2.0.2
Conflicts: NEWS.md
NULL
now sets valueFixes #810