I have found myself dealing with long, nested, ragged lists (culled from external APIs) and would like to perform some cleaning and strong-typing on them. I'm just about to write a recursive wrapper around
purrr::modify_if, but figured I'd ask here first if this is already baked in to
purrr and I just haven't managed to figure it out yet.
Here's a trivial example:
x <- list(list(a = as.character(1), b = as.double(2)), c = as.character(3), d = as.double(4)) str(x)
List of 3 $ :List of 2 ..$ a: chr "1" ..$ b: num 2 $ c: chr "3" $ d: num 4
Now I'd like to recursively convert all characters into integers, sort of like so (with a make-believe .recursive=TRUE option):
modify_if(x, is.character, as.integer, .recursive = TRUE)
Does anything like this already exist?