R/utils.R

Defines functions deparse_to_string is_infix is_pipe

.pipes <- c("%>%")

#' @importFrom rlang %||%
NULL

is_pipe <- function(x) {
  if (is.character(x)) x <- parse(text = x)[[1]]
  ifelse(is.call(x), as.character(x[[1]]) %in% .pipes, FALSE)
}

.infixes <- c("+", "-", "*", "/", "^", "%%", "%/%", "%in%")

is_infix <- function(x) {
  if (is.character(x)) x <- parse(text = x)[[1]]
  ifelse(is.call(x), as.character(x[[1]]) %in% .infixes, FALSE)
}

deparse_to_string <- function(x, width.cutoff = 500L, ...) {
  paste0(deparse(x, width.cutoff = width.cutoff, ...), collapse = "\n")
}
cgamboasanabria/gradethis documentation built on June 11, 2020, 12:15 a.m.