R/utils-recode.R

Defines functions detect_stay_switch get_math_operation

#' @keywords internal
#' @importFrom dplyr case_when

get_math_operation <- function(x) {
  return (case_when(grepl("[+]", x) ~ "addition",
                    grepl("[-]", x) ~ "subtraction",
                    grepl("[x]", x) ~ "multiplication",
                    TRUE ~ NA_character_))
}

#' @keywords internal
#' @importFrom dplyr if_else

detect_stay_switch <- function(x) {
  return (if_else(x == dplyr::lag(x),
                  "stay",
                  "switch",
                  missing = "stay"))
}

#' @keywords internal

na_if_true <- function (x, condition) {
  x[condition] <- NA
  return (x)
}

#' @keywords internal

make_lagged_col <- function (col) {
  col = paste0("prev_", dplyr::lag(col))
  return (col)
}
josegallegos07/aceR documentation built on June 27, 2022, 10:25 a.m.