| 1 |
|
| 2 |
renv_rstudio_available <- function() { |
| 3 |
|
| 4 |
# NOTE: detecting whether we're running within RStudio is a bit |
| 5 |
# tricky because not all of the expected RStudio bits have been |
| 6 |
# initialized when the R session is being initialized (e.g. |
| 7 |
# when the .Rprofile is being executed) |
| 8 |
args <- commandArgs(trailingOnly = FALSE) |
| 9 |
args[[1L]] == "RStudio" || .Platform$GUI == "RStudio" |
| 10 |
|
| 11 |
} |
| 12 |
|
| 13 |
renv_rstudio_initialize <- function(project) { |
| 14 |
|
| 15 |
tools <- catch(as.environment("tools:rstudio")) |
| 16 |
if (inherits(tools, "error")) |
| 17 |
return(FALSE) |
| 18 |
|
| 19 |
if (is.null(tools$.rs.api.initializeProject)) |
| 20 |
return(FALSE) |
| 21 |
|
| 22 |
tools$.rs.api.initializeProject(project) |
| 23 |
TRUE |
| 24 |
|
| 25 |
} |
| 26 |
|
| 27 |
renv_rstudio_fixup <- function() { |
| 28 |
|
| 29 |
# if RStudio's tools are on the search path, we should try |
| 30 |
# to fix them up so that renv's own routines don't get seen |
| 31 |
tools <- catch(as.environment("tools:rstudio")) |
| 32 |
if (inherits(tools, "error")) |
| 33 |
return(FALSE) |
| 34 |
|
| 35 |
helper <- tools[[".rs.clearVar"]] |
| 36 |
if (is.null(helper)) |
| 37 |
return(FALSE) |
| 38 |
|
| 39 |
# if the helper environment has been fixed up (as e.g. by |
| 40 |
# newer versions of RStudio) then nothing to do |
| 41 |
if (identical(tools, environment(helper))) |
| 42 |
return(FALSE) |
| 43 |
|
| 44 |
# put common tools from base into the environment |
| 45 |
envir <- environment(helper) |
| 46 |
for (var in c("assign", "exists", "get", "remove", "paste")) |
| 47 |
envir[[var]] <- get(var, envir = baseenv()) |
| 48 |
|
| 49 |
TRUE |
| 50 |
|
| 51 |
} |