Browse Source

Bring back parse_formula for retrocompatibility

And mark it deprecated

This reverts commit e2bb4ec3e2.
tags/0.2.0^2
Maxime Wack 2 years ago
parent
commit
33505c1208
1 changed files with 39 additions and 0 deletions
  1. +39
    -0
      R/utils.R

+ 39
- 0
R/utils.R View File

@@ -42,6 +42,45 @@ set_desctable_class <- function(x) {
}


#' Parse a formula
#'
#' Parse a formula defining the conditions to pick a stat/test
#'
#' Parse a formula defining the conditions to pick a stat/test
#' and return the function to use.
#' The formula is to be given in the form of
#' conditional ~ T | F
#' and conditions can be nested such as
#' conditional1 ~ (conditional2 ~ T | F) | F
#' The FALSE option can be omitted, and the TRUE can be replaced with NA
#'
#' @param x The variable to test it on
#' @param f A formula to parse
#' @return A function to use as a stat/test
parse_formula <- function(x, f) {
parse_f <- function(x) {
if (length(x) == 1) as.character(x)
else {
if (as.character(x[[1]]) == "~") {
paste0("if (", parse_f(x[[2]]), "(x)) ",
"{",
parse_f(x[[3]]),
"}")
} else if (as.character(x[[1]]) == "|") {
paste0(parse_f(x[[2]]),
"} else ",
"{",
parse_f(x[[3]]))
} else if (as.character(x[[1]]) == "(") {
parse_f(x[[2]])
}
}
}

eval(parse(text = parse_f(f)))
}


#' Build the header for pander
#'
#' @param head A headerList object


Loading…
Cancel
Save