Skip to content

Commit

Permalink
run styler on template-activate.R
Browse files Browse the repository at this point in the history
  • Loading branch information
fh-mthomson committed Oct 24, 2024
1 parent 23fcfb2 commit a23184e
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions templates/template-activate.R
Original file line number Diff line number Diff line change
@@ -1,45 +1,48 @@

local({

# the requested version of renv
version <- ..version..
attr(version, "sha") <- ..sha..

# the project directory
project <- Sys.getenv("RENV_PROJECT")
if (!nzchar(project))
if (!nzchar(project)) {
project <- getwd()
}

# use start-up diagnostics if enabled
diagnostics <- Sys.getenv("RENV_STARTUP_DIAGNOSTICS", unset = "FALSE")
if (diagnostics) {
start <- Sys.time()
profile <- tempfile("renv-startup-", fileext = ".Rprof")
utils::Rprof(profile)
on.exit({
utils::Rprof(NULL)
elapsed <- signif(difftime(Sys.time(), start, units = "auto"), digits = 2L)
writeLines(sprintf("- renv took %s to run the autoloader.", format(elapsed)))
writeLines(sprintf("- Profile: %s", profile))
print(utils::summaryRprof(profile))
}, add = TRUE)
on.exit(
{
utils::Rprof(NULL)
elapsed <- signif(difftime(Sys.time(), start, units = "auto"), digits = 2L)
writeLines(sprintf("- renv took %s to run the autoloader.", format(elapsed)))
writeLines(sprintf("- Profile: %s", profile))
print(utils::summaryRprof(profile))
},
add = TRUE
)
}

# figure out whether the autoloader is enabled
enabled <- local({

# first, check config option
override <- getOption("renv.config.autoloader.enabled")
if (!is.null(override))
if (!is.null(override)) {
return(override)
}

# if we're being run in a context where R_LIBS is already set,
# don't load -- presumably we're being run as a sub-process and
# the parent process has already set up library paths for us
rcmd <- Sys.getenv("R_CMD", unset = NA)
rlibs <- Sys.getenv("R_LIBS", unset = NA)
if (!is.na(rlibs) && !is.na(rcmd))
if (!is.na(rlibs) && !is.na(rcmd)) {
return(FALSE)
}

# next, check environment variables
# TODO: prefer using the configuration one in the future
Expand All @@ -51,29 +54,28 @@ local({

for (envvar in envvars) {
envval <- Sys.getenv(envvar, unset = NA)
if (!is.na(envval))
if (!is.na(envval)) {
return(tolower(envval) %in% c("true", "t", "1"))
}
}

# enable by default
TRUE

})

# bail if we're not enabled
if (!enabled) {

# if we're not enabled, we might still need to manually load
# the user profile here
profile <- Sys.getenv("R_PROFILE_USER", unset = "~/.Rprofile")
if (file.exists(profile)) {
cfg <- Sys.getenv("RENV_CONFIG_USER_PROFILE", unset = "TRUE")
if (tolower(cfg) %in% c("true", "t", "1"))
if (tolower(cfg) %in% c("true", "t", "1")) {
sys.source(profile, envir = globalenv())
}
}

return(FALSE)

}

# avoid recursion
Expand All @@ -94,8 +96,9 @@ local({
library(utils, lib.loc = .Library)

# unload renv if it's already been loaded
if ("renv" %in% loadedNamespaces())
if ("renv" %in% loadedNamespaces()) {
unloadNamespace("renv")
}

# load bootstrap tools ${BOOTSTRAP}

Expand All @@ -115,5 +118,4 @@ local({
renv_bootstrap_exec(project, libpath, version)

invisible()

})

0 comments on commit a23184e

Please sign in to comment.