R/print_help_console.R

Defines functions print_help_console

Documented in print_help_console

#' Print help information on console
#' @import tools
#' @export

print_help_console <- function(
                               topic,
                               format = c("text", "html", "latex", "Rd"),
                               lines = NULL,
                               before = NULL,
                               after = NULL) {
  format <- match.arg(format)
  if (!is.character(topic)) topic <- deparse(substitute(topic))
  helpfile <- utils:::.getHelpFile(help(topic))
  hs <- capture.output(switch(format,
    text = tools:::Rd2txt(helpfile),
    html = tools:::Rd2HTML(helpfile),
    latex = tools:::Rd2latex(helpfile),
    Rd = tools:::prepare_Rd(helpfile)
  ))
  hs <- gsub("_\b", "", hs)
  if (!is.null(lines)) hs <- hs[lines]
  hs <- c(before, hs, after)
  cat(hs, sep = "\n")
  invisible(hs)
}
likanzhan/acqr documentation built on Dec. 2, 2020, 10:14 a.m.