R/cleanAndGo.R

Defines functions cleanAndGo

Documented in cleanAndGo

#' Clean the environment and run the active script
#'
#' @export
cleanAndGo <- function() {

  ctx <- rstudioapi::getActiveDocumentContext()

  if (!is.null(ctx)) {

    do.call(rm, as.list(ls(all.names = TRUE, envir = .GlobalEnv)), envir = .GlobalEnv)

    tf <- tempfile(fileext = ".R")
    writeLines(ctx$contents, con = tf)

    source(tf, local = FALSE)

  }

}
hrbrmstr/hrbraddins documentation built on Oct. 20, 2019, 7:43 a.m.