R/addins.R

Defines functions quick_script quick_header

# Addin for quickly creating a new script

#' @importFrom rstudioapi showPrompt
quick_script <- function() {
  if (dir.exists("scripts")) {
    path <- "scripts"
  } else {
    path <- "."
  }
  opts <- getOption("arsenal", default = list())
  name <- rstudioapi::showPrompt(
    title = "Create a new script",
    message = "Name (without extension) :",
    default = "script"
  )
  if (is.null(name))
    return(invisible())
  create_script(path = path, name = name, author = opts$author)
}



# Addin for quickly add an header to a script
#' @importFrom rstudioapi showPrompt
quick_header <- function() {
  title <- rstudioapi::showPrompt(
    title = "Add a header",
    message = "Title :",
    default = " "
  )
  opts <- getOption("arsenal", default = list())
  header <- paste(
    "",
    "#  ------------------------------------------------------------------------",
    "#",
    paste0("# Title : ", title),
    paste0("#    By : ", opts$author),
    paste0("#  Date : ", format(Sys.Date(), format = "%F")),
    "#",
    "#  ------------------------------------------------------------------------",
    "",
    sep = "\n"
  )
  rstudioapi::insertText(location = c(1, 1), text = header)
}
jimbrig2011/arsenal documentation built on July 12, 2019, 12:25 p.m.