I am using the newly minted dplyr 1.0.0 and the digest package to generate a hash of every row in a tibble.
I am aware of
adding hash to each row using dplyr and digest in R
but I would like to use the revamped rowwise() in dplyr 1.0.0.
See the example below. Anyone has any idea about why it fails? I should be allowed to digest a row where the entries are of different types.
library(dplyr)
library(digest)
df <- tibble(
student_id = letters[1:4],
student_id2 = letters[9:12],
test1 = 10:13,
test2 = 20:23,
test3 = 30:33,
test4 = 40:43
)
df
#> # A tibble: 4 x 6
#> student_id student_id2 test1 test2 test3 test4
#> <chr> <chr> <int> <int> <int> <int>
#> 1 a i 10 20 30 40
#> 2 b j 11 21 31 41
#> 3 c k 12 22 32 42
#> 4 d l 13 23 33 43
dd <- df %>%
rowwise(student_id) %>%
mutate(hash = digest(c_across(everything()))) %>%
ungroup
#> Error: Problem with `mutate()` input `hash`.
#> ✖ Can't combine `student_id2` <character> and `test1` <integer>.
#> ℹ Input `hash` is `digest(c_across(everything()))`.
#> ℹ The error occured in row 1.
### but digest should not care too much about the type of the input
Created on 2020-06-04 by the reprex package (v0.3.0)
df %>% mutate(hash = pmap_chr(., ~ digest(c(...))))- akrun