This analysis focused on plotting data related to the food consumption of Brazilian children aged 2 to 4 years, as monitored by Brazil’s Food and Nutrition Surveillance System (SISVAN) in 2019.
get_data<-function(sheet,ss="1nnDzHKufJGujXiuCFb6Hj14k0HIt6JPV0Y2wnqa2eAc",sheet_ignore=c("Documentation", "Codebook", "Validation", "Template")){checkmate::assert_string(sheet)checkmate::assert_string(ss)checkmate::assert_character(sheet_ignore)rutils:::assert_internet()ss<-googlesheets4::gs4_get(ss)sheets<-ss$sheets$name[!ss$sheets$name%in%sheet_ignore]checkmate::assert_subset(sheet, sheets)if(!sheet=="City validation"){cities<-googlesheets4::read_sheet( ss =ss, sheet ="City validation", col_names =TRUE, col_types ="c", na =c("", "NA"), trim_ws =TRUE, skip =0)|>magrittr::extract2("value")}out<-googlesheets4::read_sheet( ss =ss, sheet =sheet, col_names =TRUE, col_types ="c", na =c("", "NA"), trim_ws =TRUE, skip =0)if(!sheet=="City validation"){out|>dplyr::mutate(n =as.integer(n))|>dplyr::filter(!n==0)}else{out}}
Code
assert_color<-function(color, null_ok=FALSE, na_ok=FALSE){color_pattern<-"(?i)^#[a-f0-9]{3}$|^#[a-f0-9]{6}$|^transparent$"checkmate::assert_flag(null_ok)checkmate::assert_flag(na_ok)name<-deparse(substitute(color))if(is.null(color)&&isFALSE(null_ok)){cli::cli_abort(paste0("{.strong {cli::col_red(name)}} cannot be {.strong NULL}."))}if(!is.null(color)){if(is.na(color)&&isFALSE(na_ok)){cli::cli_abort(paste0("{.strong {cli::col_red(name)}} cannot be {.strong NA}."))}}if(!is.null(color)&&!is.na(color)&&!color%in%grDevices::colors()&&!checkmate::test_string(color, pattern =color_pattern)){cli::cli_abort(paste0("{.strong {cli::col_red(name)}} is not a valid color code. ","It must contain a hexadecimal color code or one of the ","values in {.strong {cli::col_blue('grDevices::color()')}}."))}invisible(NULL)}
Code
assert_color_options<-function(color_low=NULL, color_high=NULL, viridis=NULL){viridis_choices<-c("magma", "A", "inferno", "B", "plasma", "C", "viridis", "D","cividis", "E", "rocket", "F", "mako", "G", "turbo", "H")color_pattern<-"(?i)^#[a-f0-9]{6}$"checkmate::assert_string(color_low, pattern =color_pattern, null.ok =TRUE)checkmate::assert_string(color_high, pattern =color_pattern, null.ok =TRUE)checkmate::assert_choice(viridis, viridis_choices, null.ok =TRUE)if(is.null(color_low)&&!is.null(color_high)||!is.null(color_low)&&is.null(color_high)){cli::cli_abort(paste0("You must provide both ", "{.strong {cli::col_blue('color_low')}} and ","{.strong {cli::col_red('color_high')}} ","arguments at the same time."))}elseif((!is.null(color_low)|!is.null(color_high))&&!is.null(viridis)){cli::cli_abort(paste0("You can't use both ", "{.strong {cli::col_blue('color_low/color_high')}} and ","{.strong {cli::col_red('viridis')}} ","arguments at the same time."))}else{invisible(NULL)}}