R/insert_srcmake.R

Defines functions insert_srcmake_addin

Documented in insert_srcmake_addin

#' Insert source('make.R') to console
#'
#' This addin only works when using RStudio. Call this function as an addin to
#' print source("make.R") to console. Optionally it is possible to assign a custom
#' keybinding (see RStudio/Tools/Modify keyboard shortcuts... and search for
#' "Execute source('make.R')").
#' @author Frederik Sachser
#' @export
insert_srcmake_addin <- function() {
  filesWD <-
    list.files(path = getwd(),
               recursive = TRUE,
               full.names = TRUE)
  
  minusBA <- grep(pattern = "BACKUP", x = filesWD)
  
  if (length(minusBA) > 0) {
    filesWD <- filesWD[-minusBA]
  }

  themake <- filesWD[basename(filesWD) %in% "make.R"]

  if (length(themake) != 1) {
    rstudioapi::sendToConsole(
      code = stop("Cannot locate file 'make.R'. Open manually."),
      execute = TRUE
    )
  } else {
    rstudioapi::sendToConsole(paste0("source('", themake, "')"), execute = FALSE)
  }
}
sachserf/repres documentation built on May 29, 2019, 12:21 p.m.