'Modifying a function to print NA when the a warning message is printed in R
I'm trying to modify a function to print NA when the function prints a warning message. I've tried using a return(NA) modifier, which you'll see in the function, but it is ineffective.
The function is below:
jobInfo <- function(list, type = c("jt", "k", "s", "a", "wa", "wc", "ws", "wv", "e", "tool", "tech", "task")){
dict <- data.frame(arg = c("jt", "k", "s", "a", "wa", "wc", "ws", "wv", "e", "tool", "tech", "task"), full = c("occupation", "knowledge", "skills", "abilities", "work_activities", "work_context", "work_styles", "work_values","education", "tools_technology", "tools_technology", "tasks"),
depth = c(2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1), secondary = c("sample_of_reported_job_titles", "", "", "", "", "", "", "", "level_required", "tools", "technology", "")) key <- as.character(dict$full[which(dict$arg == type)]) depth <- dict$depth[which(dict$arg == type)] if(depth == 2){ second_level <- dict$secondary[which(dict$arg == type)] if(length(list[[as.character(key)]][[as.character(second_level)]]) > 0){ info <- ldply((lapply(list[[as.character(key)]][[as.character(second_level)]], function(x){t(unlist(x))}))) return(info) } else{ message("Warning: This type of data is missing or incomplete for this occupation.") return(NA) } } else{ if(length(list[[key]]) > 0){ info <- ldply((lapply(list[[key]], function(x){t(unlist(x))}))) return(info) } else{ message("Warning: This type of data is missing or incomplete for this occupation.") return(NA) } } }
Any advice?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|