signaturescience / skater

SKATE R Utilities
https://signaturescience.github.io/skater/
Other
9 stars 5 forks source link

Convert `degree_truth` to character early #56

Closed DavisVaughan closed 2 years ago

DavisVaughan commented 2 years ago

We are updating tidyr::replace_na() to utilize vctrs, and that results in slightly stricter / more correct type conversions. See https://github.com/tidyverse/tidyr/pull/1219

We noticed in revdeps that this package was broken. An easy way to reproduce is to install the dev version of tidyr and run the vignette, where you will get something like:

kinpairs_inferred <- kinpairs %>% 
  dplyr::mutate(degree_truth=kin2degree(k, max_degree=3)) %>% 
  dplyr::mutate(degree_truth=tidyr::replace_na(degree_truth, "unrelated")) %>% 
  dplyr::mutate(degree_inferred=randomflip(degree_truth))
#> Error: Problem with `mutate()` column `degree_truth`.
#> ℹ `degree_truth = tidyr::replace_na(degree_truth, "unrelated")`.
#> x Can't convert `replace` <character> to match type of `data` <integer>.

The problem boils down to the fact that you are trying to replace values in an integer column, degree_truth, with a character replacement value, "unrelated". This is no longer allowed. To do this, you need to convert to a character column ahead of time, which is what this PR does.