R/makeRStudioExtras.R

Defines functions .rstudioProjOrNA .analysisFileOrNA .inRStudio

## modifys

.inRStudio = function() {
    requireNamespace("rstudioapi", quietly = TRUE) &&
        !is(tryCatch(rstudioapi::versionInfo(), error = function(x) x),
            "error")
    }

    
.analysisFileOrNA = function() {
    if(.inRStudio())
        tryCatch(rstudioapi::getSourceEditorContext()[["path"]],
                 error = function(x) NA_character_)
    else
        NA_character_
}


.rstudioProjOrNA = function() {
    
    proj = NA_character_
    if(.inRStudio()) {
        proj = rstudioapi::getActiveProject()
        if(is.null(proj)) proj = NA_character_
    }
    proj
}
        

Try the trackr package in your browser

Any scripts or data that you put into this service are public.

trackr documentation built on May 24, 2021, 5:09 p.m.