Skip to content

Commit

Permalink
Resubmission of #143 (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisVaughan authored and hadley committed Dec 11, 2018
1 parent 852c428 commit 7f30784
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/size.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ vec_slice <- function(x, i) {
NULL
} else if (is.data.frame(x)) {
# Much faster, and avoids creating rownames
out <- lapply(x, `[`, i)
out <- lapply(x, vec_slice, i)
vec_restore(out, x)
} else if (is_vector(x)) {
d <- vec_dims(x)
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-size.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ test_that("can subset object of any dimensionality", {
expect_equal(vec_slice(x4, 1L), ones(1, 3, 4, 5))
})

test_that("can subset data frame columns", {
df <- data.frame(x = 1:2)
df$y <- data.frame(a = 2:1)

expect_equal(vec_slice(df, 1L)$y, vec_slice(df$y, 1L))
})

test_that("can modify subset", {
x1 <- c(2, 1)
vec_slice(x1, 1L) <- 1
Expand Down

0 comments on commit 7f30784

Please sign in to comment.