Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run styler on template-activate.R #2025

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()

})
Loading