Skip to content

Commit

Permalink
Let unnest work with non-syntactic names.
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed May 22, 2016
1 parent f6d0365 commit a41e127
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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).

Expand Down
3 changes: 2 additions & 1 deletion R/unnest.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-unnest.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down

0 comments on commit a41e127

Please sign in to comment.