Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

column_subset evaluating [ in the frame #3926

Merged
merged 3 commits into from
Oct 18, 2018
Merged

Conversation

romainfrancois
Copy link
Member

so that we get the same results as if [ was called locally in the function, e.g.

test_that("column_subset respects S3 local [. method (#3923)", {
  testS3Class <- function(x, X){
    structure(x, class = "testS3Class", X = X)
  }
  `[.testS3Class` <- function(x, i, ...) {
    testS3Class(unclass(x)[i, ...], X = attr(x, "X"))
  }
  df <- tibble(x = rep(1:2, each = 5), y = testS3Class(1:10, X = 100))
  res <- df %>%
    group_by(x) %>%
    summarise(chunk = list(y))
  expect_equal(res$chunk[[1]], df$y[df$x == 1])
  expect_equal(res$chunk[[1]], df$y[df$x == 1])

  df$y <- testS3Class(matrix(1:20, ncol = 2), X = 200)
  res <- df %>%
    group_by(x) %>%
    summarise(chunk = list(y))
  expect_equal(res$chunk[[1]], df$y[df$x == 1, , drop = FALSE])
  expect_equal(res$chunk[[1]], df$y[df$x == 1, , drop = FALSE])
})

@romainfrancois romainfrancois merged commit bcaff7b into master Oct 18, 2018
@romainfrancois romainfrancois deleted the fix-3923/subset-frame branch October 18, 2018 14:14
@lock
Copy link

lock bot commented Apr 16, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Apr 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants