~hrbrmstr/epidata

ref: e12c13d229ba5f2ca9a4300ed38971676e68b20f epidata/R/utils.r -rw-r--r-- 680 bytes
e12c13d2hrbrmstr fixed CRAN checks; added 4 new functions; added UA 1 year, 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
make_params <- function(params, by, ok="") {

  by <- stringi::stri_trans_tolower(by)
  by <- stringi::stri_replace_all_regex(by, "[[:space:]]", "")
  by <- strsplit(by, "")[[1]]
  by <- purrr::keep(by, `%in%`, ok)
  by <- sort(unique(by))

  params <- c(params, setNames(as.list(rep("*", length(by))), by))

}

.clean_cols <- function(x) {

  x <- stringi::stri_replace_all_fixed(x, ",", "")

  if (any(grepl("%", x))) {
    as.numeric(stringi::stri_replace_all_fixed(x, "%", ""))/100
  } else if (any(grepl("\\$", x))) {
    as.numeric(stringi::stri_replace_all_fixed(x, "$", ""))
  } else {
    x
  }

}

clean_cols <- function(x) {
  suppressWarnings(
    .clean_cols(x)
  )
}