diff --git a/R/db.R b/R/db.R index 637ebd9..6009d14 100644 --- a/R/db.R +++ b/R/db.R @@ -111,7 +111,9 @@ nvals <- function(x){ #' simpleCap(my_string) simpleCap <- function(x) { stopifnot(class(x) == "character") - s <- strsplit(x, " ")[[1]] - paste(toupper(substring(s, 1,1)), substring(s, 2), - sep = "", collapse = " ") + sapply(x, function(word) { + s <- strsplit(word, " ")[[1]] + paste(toupper(substring(s, 1, 1)), substring(s, 2), + sep = "", collapse = " ") + }) } diff --git a/R/utils.R b/R/utils.R index b1a0ca3..89c2bab 100644 --- a/R/utils.R +++ b/R/utils.R @@ -31,7 +31,7 @@ safe_max <- function(x) { #' pretty_per(0.2, ndigit = 1) #' pretty_per(c(0.2, 0.332423, 0.4, 0.342342), ndigit = 2) pretty_per <- function(x, ndigit = 1) { - if (any(x >= 100) & !all(is.na(x))) { + if (any(x >= 100) && !all(is.na(x))) { message("Values over 100 found, did you mean to use proportions?") } x <- format(round(x, digits = ndigit + 2) * 100, nsmall = ndigit) @@ -283,7 +283,7 @@ get_stabbr <- function(fips) { fips_codes <- fips_codes[!duplicated(fips_codes),] if (length(fips) != 1) { out <- rep(NA, length(fips)) - for (i in length(fips)) { + for (i in seq_along(fips)) { out[i] <- fips_codes[fips_codes$state_code == fips, 1] } @@ -375,7 +375,7 @@ random_round <- function(x) { add = rep(as.integer(0),length(r)) add[r>test] <- as.integer(1) value = v + add - ifelse(is.na(value) | value<0, 0, value) + value <- ifelse(is.na(value) | value < 0, 0, value) return(value) }