Skip to content

Commit

Permalink
Fix 'to_df' for list of unnamed vectors argument
Browse files Browse the repository at this point in the history
  • Loading branch information
gdemin committed Apr 27, 2020
1 parent 5519b5c commit 2528262
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/to_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ to_df = function(data,
)
for(i in seq_along(res)){
if(!is.null(res[[i]]) && !is.list(res[[i]])){
res[[i]] = as.list(res[[i]])
res[[i]] = as.data.table(as.list(res[[i]]))
}
}
idvalue_expr = substitute(idvalue)
Expand Down
5 changes: 5 additions & 0 deletions inst/tinytest/test_to_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ expect_identical(
cat("\nContext:","to_df", "\n")

data("mtcars")

expect_identical(
to_df(list(1:2, 2:3, 3:4)),
data.table(V1 = 1:3, V2 = 2:4)
)
expect_identical(
to_df(mtcars, list(var = .name, mean = mean(.x), sd = sd(.x))),
data.table(var = names(mtcars), mean = colMeans(mtcars), sd = sapply(mtcars, sd))
Expand Down

0 comments on commit 2528262

Please sign in to comment.