However, extending to a much larger database, I obtain the following error:
Error: Problem with `mutate()` column `cr`.
i `cr = map(data, addCrit, df2)`.
x Problem with `mutate()` column `crit`.
i `crit = map_dbl(data, crit, df_1)`.
x Result 1 must be a single double, not a double vector of length 4
Run `rlang::last_error()` to see where the error occurred.
Does anyone know what this error refers to and how I can solve for it?
perhaps adding logging would help you isolate the problematic data ?
Something like adding print statements. then looking to see the last one that attempted but failed.
addCrit = function(df_1, df_2){
print("addCrit:attempting to process")
print(head(df1))
print(head(df2))
r <- df_2 %>%
filter(type1==df_1$type1 & type2==df_1$type2) %>%
nest(data=criteria1:criteria4) %>%
mutate(
crit = map_dbl(data, crit, df_1),
id2 = id
) %>%
arrange(crit) %>%
select(id2, crit) %>%
head(1)
print("addCrit: Done")
r
}