R/rstudio-scriptPath.R

Defines functions scriptPath

Documented in scriptPath

#' Script path
#'
#' @export
#' @note Only currently works inside RStudio.
#' @note Updated 2022-10-20.
#'
#' @return `character(1)`.
#' Normalized path to current script.
#'
scriptPath <- function() {
    stopifnot(
        .requireNamespaces("rstudioapi"),
        .isRstudio()
    )
    x <- rstudioapi::getSourceEditorContext()[["path"]]
    stopifnot(.isAFile(x))
    x <- .realpath(x)
    x
}
mjsteinbaugh/devtools documentation built on Jan. 5, 2024, 11:09 a.m.