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

Keep classes set on an object after filtering #3818

Closed
torbjorn opened this issue Sep 14, 2018 · 2 comments
Closed

Keep classes set on an object after filtering #3818

torbjorn opened this issue Sep 14, 2018 · 2 comments

Comments

@torbjorn
Copy link

filtering something drops any existing classes and adds just data.frame it seems.

    library(dplyr)
    d <- cars
    class( d ) <- c( "cars", "data.frame" )
    print.cars <- function( x, ... ) { print.data.frame( head( d, n=2 ) ); cat("...\n") }
    d
    class( d )
    class( d %>% filter( speed < 10 ) )
    d %>% filter( speed < 10 )

would be nice if my object kept its classes after filtering

print(d) # produces:

    > d
      speed dist
    1     4    2
    2     4   10
    ...

print(d %>% filter( speed < 10 )) # produces:

    > d %>% filter( speed < 10 )
      speed dist
    1     4    2
    2     4   10
    3     7    4
    4     7   22
    5     8   16
    6     9   10
@hadley
Copy link
Member

hadley commented Sep 14, 2018

Duplicate of #2432

@hadley hadley marked this as a duplicate of #2432 Sep 14, 2018
@hadley hadley closed this as completed Sep 14, 2018
@lock
Copy link

lock bot commented Mar 13, 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 Mar 13, 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

No branches or pull requests

2 participants