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

For S4 objects, character indexing should use slots #200

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

For S4 objects, character indexing should use slots #200

hadley opened this issue May 19, 2016 · 2 comments
Labels

Comments

@hadley
Copy link
Member

@hadley hadley commented May 19, 2016

e.g. https://twitter.com/expersso/status/733220790557155328

@peterchristofferholm
Copy link

@peterchristofferholm 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
Copy link
Member Author

@hadley 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants