Open
Description
Rowwise operations on epi_df
s lose epi_df
-ness.
library(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
library(epiprocess)
#>
#> Attaching package: 'epiprocess'
#> The following object is masked from 'package:stats':
#>
#> filter
toy_epi_df = new_epi_df(tibble(geo_value=1, time_value=1:5, cases=1:5))
toy_epi_df %>% rowwise() %>% mutate(geo_value2 = geo_value)
#> # A tibble: 5 × 4
#> # Rowwise:
#> geo_value time_value cases geo_value2
#> <dbl> <int> <int> <dbl>
#> 1 1 1 1 1
#> 2 1 2 2 1
#> 3 1 3 3 1
#> 4 1 4 4 1
#> 5 1 5 5 1
toy_epi_df %>% rowwise() %>% group_split()
#> <list_of<
#> tbl_df<
#> geo_value : double
#> time_value: integer
#> cases : integer
#> >
#> >[5]>
#> [[1]]
#> # A tibble: 1 × 3
#> geo_value time_value cases
#> <dbl> <int> <int>
#> 1 1 1 1
#>
#> [[2]]
#> # A tibble: 1 × 3
#> geo_value time_value cases
#> <dbl> <int> <int>
#> 1 1 2 2
#>
#> [[3]]
#> # A tibble: 1 × 3
#> geo_value time_value cases
#> <dbl> <int> <int>
#> 1 1 3 3
#>
#> [[4]]
#> # A tibble: 1 × 3
#> geo_value time_value cases
#> <dbl> <int> <int>
#> 1 1 4 4
#>
#> [[5]]
#> # A tibble: 1 × 3
#> geo_value time_value cases
#> <dbl> <int> <int>
#> 1 1 5 5
Created on 2023-03-15 with reprex v2.0.2
We may want the first case to work if we have more complicated data in a list column to manipulate with non-vectorized functions. We may want the latter to work, e.g., to simplify internals of #275 when faced with 0 vs. non-0 row epi_df
s, though this probably also means implementing some stuff in pillars
and/or vctrs
.