Skip to content
New issue

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

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

Already on GitHub? # to your account

tidyselect #193

Open
juangomezduaso opened this issue May 29, 2019 · 0 comments
Open

tidyselect #193

juangomezduaso opened this issue May 29, 2019 · 0 comments

Comments

@juangomezduaso
Copy link

Thinking of rray as a tidyverse citizen, a couple of ideas came to my mind. I will put them in sepparate issues so as they can be independently commented on, dismissed or kept as future posible features.
The first one is the use of tidyselect in rray indexes. To do things like:
x[y2011:y2019, -NY]

As an appetizer I have done a dummy trial (for the simpler case of rray_slice instead of rray_subset ):

library(rray)
#> Warning: package 'rray' was built under R version 3.5.3
library(vctrs)
#> Warning: package 'vctrs' was built under R version 3.5.3
library(rlang)
#> Warning: package 'rlang' was built under R version 3.5.3
library(tidyselect)
#> Warning: package 'tidyselect' was built under R version 3.5.3
funrray_slice <- function (x, i, axis) {
  i <- vars_select(dimnames(x)[[axis]],!!enquo(i))
  axis <- vec_cast(axis, integer())
  rray:::validate_axis(axis, x)
  indexer <- rray:::front_pad(i, axis)
  rray_subset(x, !!!indexer)
}
x <- rray(1:8,c(2,4),list(c("A","B"),letters[1:4])) 
funrray_slice(x, -b  , axis=2)
#> <rray<int>[,3][6]>
#>   a c d
#> A 1 5 7
#> B 2 6 8
# I wasn`t seeking it, but one of the goodies of tidyselect
# solves the issue of easy referencing the end of axis:
funrray_slice(x, 1:last_col() , axis=2)
#> <rray<int>[,4][8]>
#>   a b c d
#> A 1 3 5 7
#> B 2 4 6 8

Created on 2019-05-29 by the reprex package (v0.2.1)

This enhancement is only applicable to "Fully and Uniquely Named" rrays ("funrrays"; not to mean that numeric-index based rrays are boring ;).
I dont know if they deserve their own class or even their own package. I'd rather see rray supply all this names based functionality seamlessly. With names, more thing become possible and rray can make inroads into dplyr territory taking there its own strong points.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant