Hello,
I have a list of lists that are unique surveys and I am trying to find a way to only keep lists that meet a condition. For example, keep lists that contain the variable Q4 and Q4 must be numeric or integer.
I apologize for not being able to provide reproducible code at the moment. I am using an API to obtain my surveys from Qualtrics using this function. As you can see, I can't find the right way to filter these lists based on the logic that Q4 is numeric of integer. I was thinking that assertthat functions might work but no luck...
GetQualSurvey <- function(token, user)
{
registerOptions(api_token=token, root_url="")
Surveys <- getSurveys() %>%
filter(id %in% user) %>%
select(id) %>%
mutate(id = as.character(id))
Vector <- Surveys[['id']]
map(Vector, getSurvey, force_request = T, useLabels = F) %>%
map2(Vector, ~mutate(.x, ID = .y)) %>%
keep(~ assertthat::has_name(.x,"Q4")) %>%
keep(~ assertthat::is.number(Q4)) %>%
map(~ mutate(.x, Q4 = as.integer(Q4))) %>%
map(~ select(.x, ResponseID, StartDate, EndDate,
RecipientEmail, Finished,Q4, ID)) %>%
reduce(bind_rows)
}
Thank you for the help!