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

For S4 objects, character indexing should use slots #200

Closed
hadley opened this Issue May 19, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@hadley
Member

hadley commented May 19, 2016

@peterchristofferholm

This comment has been minimized.

peterchristofferholm commented Jun 17, 2018

I can't seem to access S4-object slots through character indexing directly in map_*. However, it works as intended with pluck. AFAIK the selection in map is powered by pluck so it seems weird that it does not work. See reprex:

s4_obj <- setClass(
  "test object",
  slots = c(first_slot = "numeric",
            second_slot = "logical"),
  
  prototype = list(first_slot = 1:10,
                   second_slot = TRUE)
)

example <- s4_obj()

example
#> An object of class "test object"
#> Slot "first_slot":
#>  [1]  1  2  3  4  5  6  7  8  9 10
#> 
#> Slot "second_slot":
#> [1] TRUE

example %>% map("first_slot")
#> Error: `.x` is not a vector (S4)

example %>% pluck("first_slot")
#>  [1]  1  2  3  4  5  6  7  8  9 10

EDIT: Nevermind, it seems as if this functionality of map has been moved to the pluck function.

@hadley

This comment has been minimized.

Member

hadley commented Jun 17, 2018

You need to put the object in order for it to work with map.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment