-
Notifications
You must be signed in to change notification settings - Fork 2
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
Exact the "output" as a new column from a collateral
class column [question]
#20
Comments
Hi @JauntyJJS! We don't have a specifically named test %>% mutate(res = map(converted_date_log, "result"))
# # A tibble: 6 × 3
# test_date converted_date_log res
# <list> <collat> <list>
# 1 <chr [1]> R _ _ _ _ <date [1]>
# 2 <chr [1]> R _ _ W _ <date [1]>
# 3 <dttm [1]> R _ _ _ _ <date [1]>
# 4 <lgl [1]> R _ _ _ _ <lgl [1]>
# 5 <dbl [1]> R _ _ W _ <date [1]>
# 6 <chr [1]> R _ _ W _ <date [1]>
test %>% mutate(res = map_vec(converted_date_log, "result"))
# # A tibble: 6 × 3
# test_date converted_date_log res
# <list> <collat> <date>
# 1 <chr [1]> R _ _ _ _ 2022-10-25
# 2 <chr [1]> R _ _ W _ NA
# 3 <dttm [1]> R _ _ _ _ 2022-10-07
# 4 <lgl [1]> R _ _ _ _ NA
# 5 <dbl [1]> R _ _ W _ NA
# 6 <chr [1]> R _ _ W _ NA (Note that although you're still using purrr twice here, you're at least not running your own function twice—the second use here is just to extract the result). You should, in theory, be able to extract other components the same way: test %>% mutate(
err = map_chr(converted_date_log, c("error", "message"), .default = NA_character_))
# # A tibble: 6 × 3
# test_date converted_date_log err
# <list> <collat> <chr>
# 1 <chr [1]> R _ _ _ _ NA
# 2 <chr [1]> R _ _ W _ NA
# 3 <dttm [1]> R _ _ _ _ NA
# 4 <lgl [1]> R _ _ _ _ NA
# 5 <dbl [1]> R _ _ W _ NA
# 6 <chr [1]> R _ _ W _ NA But warnings, messages and output can be a pain, because they return test %>% mutate(
warn = map_chr(converted_date_log, "warnings", .default = NA_character_))
# Error in `mutate()`:
# ! Problem while computing `warn =
# map_chr(converted_date_log, "warnings",
# .default = NA_character_)`.
# Caused by error in `map_chr()`:
# ℹ In index: 1.
# Caused by error:
# ! Result must be length 1, not 0.
# Run `rlang::last_error()` to see where the error occurred. That's a bit of a pain, to be frank. I might file an issue with purrr on this, because it's not clear to me why there is a difference between |
I'm also going to at @Maximilian-Stefan-Ernst, because I just spied tidyverse/purrr#843 while checking things for the issue and thought they might like collateral 😛 |
Looks like the very issue of dealing with |
Hi @jimjam-slam, Thank you for your recommendations. The suggestion is good enough for me to proceed. For now I can just manually check if there are any warnings, errors or messages. |
Hello,
I have created a function that tries to clean up text in (dd/mm/yyyy) to dates. I have included a test tibble
test_data
some bad inputs as well.Created on 2023-03-13 with reprex v2.0.2
Session info
I have managed to create a column called
converted_date_log
to see the collateral output.May I ask if there is a way to "unnest" to the output component of
converted_date_log
?For example
to give
I understand that it is possible to do it this way
but it felt like I am using
purrr
twice.The text was updated successfully, but these errors were encountered: