From a41e1279070469addcc5ddab504ea1c7d8494289 Mon Sep 17 00:00:00 2001 From: hadley Date: Sun, 22 May 2016 14:38:50 +0200 Subject: [PATCH] Let unnest work with non-syntactic names. Fixes #190 --- NEWS.md | 2 ++ R/unnest.R | 3 ++- tests/testthat/test-unnest.R | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 594541eba..2e26df2b4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # tidyr 0.4.1.9000 +* `unnest()` now works with non-syntactic names (#190). + * `unnest()` gains `.id` argument that works the same way as `bind_rows()`. This is useful if you have a named list of data frames or vectors (#125). diff --git a/R/unnest.R b/R/unnest.R index 482b34061..1e784fe98 100644 --- a/R/unnest.R +++ b/R/unnest.R @@ -60,7 +60,8 @@ unnest <- function(data, ..., .drop = NA, .id = NULL) { dots <- lazyeval::lazy_dots(...) if (length(dots) == 0) { list_cols <- names(data)[vapply(data, is.list, logical(1))] - dots <- lazyeval::as.lazy_dots(list_cols, env = parent.frame()) + list_col_names <- lapply(list_cols, as.name) + dots <- lazyeval::as.lazy_dots(list_col_names, env = parent.frame()) } unnest_(data, dots, .drop = .drop, .id = .id) diff --git a/tests/testthat/test-unnest.R b/tests/testthat/test-unnest.R index 45c048d42..4e9794664 100644 --- a/tests/testthat/test-unnest.R +++ b/tests/testthat/test-unnest.R @@ -69,6 +69,12 @@ test_that(".id creates vector of names for data frame unnest", { expect_equal(out$name, c("a", "b", "b")) }) +test_that("can use non-syntactic names", { + out <- data_frame("foo bar" = list(1:2, 3)) %>% unnest() + + expect_named(out, "foo bar") +}) + # Drop -------------------------------------------------------------------- test_that("unnest drops list cols if expanding", {