Open jkeuskamp opened 1 year ago
Hey @jkeuskamp --- this may be an unavoidable result of how the map functions need a set of objects to map over, whereas rowwise()
breaks up those sets by row. I'll have to dig more into the documentation for purrr::map()
/dplyr::rowwise()
to confirm, but for now I've added a plain-text error when trying to use a nplyr fn on a rowwise df:
library(nplyr)
#> Loading required package: dplyr
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
#> Loading required package: tidyr
df <-
tibble::tibble(group = c(1, 1, 2, 2),
parameter = c(1, 2, 1, 2),
value = c(1, 2, 3, 4)) |>
dplyr::group_by(group) |>
tidyr::nest()
df |>
nest_select(data, value)
#> # A tibble: 2 × 2
#> # Groups: group [2]
#> group data
#> <dbl> <list>
#> 1 1 <tibble [2 × 1]>
#> 2 2 <tibble [2 × 1]>
# throws better error now
df |>
ungroup() |>
rowwise() |>
nest_select(data, value)
#> Error: argument `.data` must not be a rowwise dataframe.
#> try calling `dplyr::ungroup()`
# throws error for all nplyr functions
df |>
ungroup() |>
rowwise() |>
nest_mutate(data, value = value + 1)
#> Error: argument `.data` must not be a rowwise dataframe.
#> try calling `dplyr::ungroup()`
Created on 2023-04-10 with reprex v2.0.2
Not sure if this is a bug or a feature request:
When used on rowwise nested tibbles, nest_select fails, as the objects passed to map become lists instead of dataframes. (see example below) It would be nice to issue an informative warning or error instead of the current one
with:
df <- tibble(group=c(1,1,2,2),parameter=c(1,2,1,2),value=c(1,2,3,4)) %>% group_by(group) %>% nest()
whiledf %>% nest_select(data,value)
works fine, whiledf %>% rowwise() %>% nest_select(data,value)
fails with the rather confusing error: