-
Notifications
You must be signed in to change notification settings - Fork 418
Description
Hi,
I have some code which uses a fair bit of meta programming (so a table of audit measures basically - where we have lists of the audit measure function being applied). I spotted a neat-looking optimisation to use tidyr to unnest the list.
Unfortunately, when using unnest where the list elements are functions, we get errors within the function (and presumably unpredictable behaviour). Ironically it's presumably because internally tidyr is doing exactly what my code is trying to do with the results of the function!
To demonstrate this, I used the tidyr example and converted the 'films' list-column to have functions rather than film titles (imagine we're going to pluck those functions and insert them into a later dplyr query on a table).
Brief description of the problem
df <- tibble(
character = c("Toothless", "Dory"),
metadata = list(
list(
species = "dragon",
color = "black",
films = c(
rlang::expr(.data[["title"]] == "How to Train Your Dragon"),
rlang::expr(.data[["title"]] == "How to Train Your Dragon 2"),
rlang::expr(.data[["title"]] == "How to Train Your Dragon: The Hidden World")
)
),
list(
species = "clownfish",
color = "blue",
films = c(rlang::expr(.data[["title"]] == "Finding Nemo"),
rlang::expr(.data[["title"]] == "Finding Dory"))
)
)
)
tidyr::unnest_wider(df, metadata)
tidyr::unnest_longer(df, films)
The last command to unnest films results in:
Error in eval_tidy(enquo(var), var_env) : object 'films' not found