R/utils.R

Defines functions message_info message_warn message_oops message

# change messages to blue text instead of default red

message <- function(...) {
  if (requireNamespace('usethis', quietly = TRUE)) {
    # first try use usethis messages
    x <- paste(...)
    usethis::ui_done(x)
  } else if (requireNamespace("crayon", quietly = TRUE)) {
    # otherwise crayon
    x <- paste(...)
    return(base::message(crayon::blue(paste(base::strwrap(x), collapes="\n"))))
  } else {
    return(base::message(...))
  }
}

message_oops <- function(...) {
  if (requireNamespace('usethis', quietly = TRUE)) {
    # first try use usethis messages
    x <- paste(...)
    usethis::ui_oops(x)
  } else if (requireNamespace("crayon", quietly = TRUE)) {
    # otherwise crayon
    x <- paste(...)
    return(base::message(crayon::red(paste(base::strwrap(x), collapes="\n"))))
  } else {
    return(base::message(...))
  }
}

message_warn <- function(...) {
  if (requireNamespace('usethis', quietly = TRUE)) {
    # first try use usethis messages
    x <- paste(...)
    usethis::ui_warn(x)
  } else if (requireNamespace("crayon", quietly = TRUE)) {
    # otherwise crayon
    x <- paste(...)
    return(base::message(crayon::red(paste(base::strwrap(x), collapes="\n"))))
  } else {
    return(base::message(...))
  }
}

message_info <- function(...) {
  if (requireNamespace('usethis', quietly = TRUE)) {
    # first try use usethis messages
    x <- paste(...)
    usethis::ui_info(x)
  } else if (requireNamespace("crayon", quietly = TRUE)) {
    # otherwise crayon
    x <- paste(...)
    return(base::message(crayon::green(paste(base::strwrap(x), collapes="\n"))))
  } else {
    return(base::message(...))
  }
}


tiny <- 1e-15  # define tiny variable

Try the MSEtool package in your browser

Any scripts or data that you put into this service are public.

MSEtool documentation built on Sept. 30, 2024, 9:22 a.m.