In a nested list with three levels, I need to reach the third level (i.e., resources) and check whether some special characters exist in the data. I tried to make a similar sample of data but there is still a difference I could not address. While level1 (foo) and level 2 (e.g., obj1) are lists, level 3 (resource) is list(s3:data.frame). I run the code below but as you can see there is an error when it comes to the second part (i.e., filter). Could you please tell me how to avoid this error?
obj1 <- list(resource = list(bodyPart = c("leg", "arm", "knee"),side = "RIGHT", device = "SENS"))
obj2 <- list(resource = list(bodyPart = c("leg", "arm", "knee"), side = "LEFT", device = "GOM"))
x <- list(foo = obj1, bar = obj2)
Dat <- lapply(x, function(tb) tb[sapply(tb, function(z) any(grepl("[^\x01-\x7F]", z), na.rm = TRUE))]) %>%
dplyr::filter(if_any(everything(), ~ grepl("[^\x01-\x7F]", .)))
Error in UseMethod("filter") :
no applicable method for 'filter' applied to an object of class "list"