#' Functions Focused on Active Docs
#'
#' TBD
#'
#' @param open TBD
#'
#' @importFrom rstudioapi getSourceEditorContext navigateToFile getActiveDocumentContext jobRunScript
#'
#' @name active_script
NULL
#' @describeIn active_script TBD
#' @export
job_active_script <- function(){
work_dir <- getwd()
out_path <- tempfile(fileext = ".R")
active_doc <- rstudioapi::getActiveDocumentContext()
writeLines(active_doc$contents, con = out_path)
rstudioapi::jobRunScript(path = out_path,
encoding = "UTF-8",
workingDir = work_dir,
importEnv = FALSE,
exportEnv = "R_GlobalEnv")
}
#' @describeIn active_script TBD
#' @export
write_active <- function(open = TRUE){
# Get active project and the location of the temp folder (inside inst)
curr_dir <- rstudioapi::getActiveProject()
if(is.null(curr_dir)){
out_dir <- normalizePath(file.path(tempdir(check = TRUE), "inst", "temp"), mustWork = FALSE)
}else{
out_dir <- normalizePath(file.path(curr_dir, "inst", "temp"), mustWork = FALSE)
}
# if doesnt exist, create it
if(!dir.exists(out_dir))
dir.create(out_dir, recursive = TRUE)
# Get R lines of active context file
r_lines <- readLines(path.expand(rstudioapi::getSourceEditorContext()$path))
out_path <- tempfile(tmpdir = out_dir, fileext = ".R")
writeLines(r_lines, out_path)
if(open)
rstudioapi::navigateToFile(out_path)
return(invisible(NULL))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.