You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@arrow.apache.org by "Sharla Gelfand (Jira)" <ji...@apache.org> on 2020/11/20 20:54:00 UTC

[jira] [Commented] (ARROW-10668) [R] Filtering does not work with .data pronoun

    [ https://issues.apache.org/jira/browse/ARROW-10668?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17236428#comment-17236428 ] 

Sharla Gelfand commented on ARROW-10668:
----------------------------------------

For completeness - .data seems to work fine within select() and rename()

{code:r}
library(dplyr)
library(arrow)

tmp <- tempfile()

write_dataset(mtcars, tmp, format = "parquet")

mtcars_arrow <- open_dataset(tmp)

mtcars_arrow %>%
  select(mpg_new = .data$mpg) %>%
  collect() %>%
  head()
#>   mpg_new
#> 1    21.0
#> 2    21.0
#> 3    22.8
#> 4    21.4
#> 5    18.7
#> 6    18.1

mtcars_arrow %>%
  rename(mpg_new = .data$mpg) %>%
  collect() %>%
  head()
#>   mpg_new cyl disp  hp drat    wt  qsec vs am gear carb
#> 1    21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
#> 2    21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
#> 3    22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
#> 4    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
#> 5    18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
#> 6    18.1   6  225 105 2.76 3.460 20.22  1  0    3    1
{code}

> [R] Filtering does not work with .data pronoun
> ----------------------------------------------
>
>                 Key: ARROW-10668
>                 URL: https://issues.apache.org/jira/browse/ARROW-10668
>             Project: Apache Arrow
>          Issue Type: Bug
>          Components: R
>    Affects Versions: 2.0.0
>            Reporter: Sharla Gelfand
>            Priority: Minor
>
> Filtering while using the `.data` pronoun does not work properly on arrow datasets - presumably because `.data` is meaningful for something else in arrow? `.data` doesn't always need to be used when using dplyr verbs interactively, but it is pretty much a requirement when writing packages that use the verbs, to [avoid an R CMD check note.|https://rlang.r-lib.org/reference/tidyeval-data.html]
> Curious on thoughts/workarounds for this! Thank you!
> {code:r}
> library(dplyr)
> library(arrow)
> # Filtering using .data pronoun works on regular objects
> mtcars %>%
>  filter(.data$cyl == 6)
> #> mpg cyl disp hp drat wt qsec vs am gear carb
> #> Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4
> #> Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4
> #> Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1
> #> Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1
> #> Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4
> #> Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4
> #> Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6
> # But it does not seem to on arrow data sets
> tmp <- tempfile()
> write_dataset(mtcars, tmp, format = "parquet")
> mtcars_arrow <- open_dataset(tmp)
> # Filtering works fine without the pronoun
> mtcars_arrow %>%
>  filter(cyl == 6) %>%
>  collect()
> #> mpg cyl disp hp drat wt qsec vs am gear carb
> #> 1 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4
> #> 2 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4
> #> 3 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1
> #> 4 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1
> #> 5 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4
> #> 6 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4
> #> 7 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6
> # Using the .data pronoun, does not return any data
> mtcars_arrow %>%
>  filter(.data$cyl == 6) %>%
>  collect()
> #> [1] mpg cyl disp hp drat wt qsec vs am gear carb
> #> <0 rows> (or 0-length row.names)
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)