Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
Noam Ross committed Dec 24, 2023
1 parent 3e74d34 commit 20f511d
Show file tree
Hide file tree
Showing 28 changed files with 1,621 additions and 2,131 deletions.
119 changes: 80 additions & 39 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -1,46 +1,87 @@
# Use the local user's .Rprofile when interactive.
# Good for keeping local preferences and shortcuts, but not always reproducible.
local({
user_rprof <- Sys.getenv("R_PROFILE_USER", file.path(Sys.getenv("HOME"), ".Rprofile"))
if(interactive() && file.exists(user_rprof)) source(user_rprof)
})
# The .Rprofile file is loaded at the start of every R session and can be used
# to set common options and settings. As {targets} starts a new session for each
# target, it should be limited to options and avoid loading packages or other
# heavy tasks. Messages and diagnostics should be limited to interactive sessions.

# ---- Function definitions ----------------------------------------------------
local({ # Wrapping in `local()` avoids side effects or cluttering the environment

load_env <- function(
env_files = list.files(all.files = TRUE, pattern = "^\\.env.*"),
verbose = TRUE) {
for (f in env_files) {
tryCatch(
readRenviron(f),
error = function(e) {
if (verbose) {
if (isTRUE(suppressWarnings(readBin(f, "character", 2))[2] == "GITCRYPT")) {
message("`", f, "` is encrypted, not loading. Run `git-crypt unlock`.")
} else {
message("Error reading ", f, ": ", e$message, ". Not loading.")
}
}
})
}
}

# ---- Interactive-only ------------------------------------------------------
if (interactive()) {
# Source the user's .Rprofile if it exists, but other options will clobber it
user_rprof <- Sys.getenv("R_PROFILE_USER", normalizePath("~/.Rprofile", mustWork = FALSE))
if (file.exists(user_rprof) && nzchar("USE_CAPSULE")) {
source(user_rprof)
}
load_env(verbose = TRUE)

options(
renv.config.startup.quiet = FALSE,
renv.config.synchronized.check = TRUE,
renv.config.dependency.errors = "reported"
)

if (!nzchar("USE_CAPSULE") && requireNamespace("capsule", quietly = TRUE)) {
capsule::whinge()
}


# Load .env environment variables
if (file.exists(".env")) {
if(isTRUE(suppressWarnings(readBin(".env", "character", 2))[2] == "GITCRYPT")) {
message(".env file is encrypted, not reading. Use git-crypt unlock to decrypt")

} else {
try(readRenviron(".env"))
# ---- Non-interactive only ------------------------------------------------

load_env(verbose = FALSE)
options(
renv.config.startup.quiet = TRUE,
renv.config.synchronized.check = FALSE, # Avoid the check in every sub-process
renv.config.dependency.errors = "ignored"
)
}
}

# ---- All sessions ----------------------------------------------------------
options(
renv.config.install.verbose = TRUE # See what is happening when packages are installed
)

if (requireNamespace("renv", quietly = TRUE)) {
renv::settings$ignored.packages(c("ehaproj", "tflow", "fnmate"))
}

if (!nzchar("USE_CAPSULE")) {
source("renv/activate.R")
load_env(verbose = FALSE) # Load again because renv can clobber env vars
}


})

options(
repos = c(RSPM = "https://packagemanager.rstudio.com/all/latest",
CRAN = "https://cran.rstudio.com/"),
renv.config.auto.snapshot = TRUE, ## Attempt to keep renv.lock updated automatically
tidyverse.quiet = TRUE
)

# Since RSPM does not provide Mac binaries, always install packages from CRAN
# on mac or windows, even if renv.lock specifies they came from RSPM
if (Sys.info()[["sysname"]] %in% c("Darwin", "Windows")) {
options(renv.config.repos.override = c(
CRAN = "https://cran.rstudio.com/",
INLA = "https://inla.r-inla-download.org/R/testing"))
} else if (Sys.info()[["sysname"]] == "Linux") {
options(renv.config.repos.override = c(
RSPM = "https://packagemanager.rstudio.com/all/latest",
INLA = "https://inla.r-inla-download.org/R/testing"))
# ---- Startup message ---------------------------------------------------------
if (interactive() && Sys.getenv("RSTUDIO") == "1") {
setHook("rstudio.sessionInit", function(newSession) {
if (newSession) {
cat("\014")
cat("\033[38;5;196m▃▃▃▃▃▃\033[39m\033[38;5;214m▃▃▃▃▃▃\033[39m\033[38;5;226m▃▃▃▃▃▃\033[39m\033[38;5;34m▃▃▃▃▃▃\033[39m\033[38;5;27m▃▃▃▃▃▃\033[39m\033[38;5;91m▃▃▃▃▃▃\033[39m")
cat("\n")
}
}, action = "append")
}

# Load the local library
if(file.exists("renv/activate.R")) source("renv/activate.R")

# If project packages have conflicts define them here, we start with common ones
if(requireNamespace("conflicted", quietly = TRUE)) {
conflicted::conflict_prefer("filter", "dplyr", quiet = TRUE)
conflicted::conflict_prefer("count", "dplyr", quiet = TRUE)
conflicted::conflict_prefer("select", "dplyr", quiet = TRUE)
conflicted::conflict_prefer("set_names", "magrittr", quiet = TRUE)
conflicted::conflict_prefer("View", "utils", quiet = TRUE)
}
1 change: 1 addition & 0 deletions .env_user
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
USE_TARGETS=1
20 changes: 10 additions & 10 deletions .github/workflows/make-targets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@ on:
# Alternately, for jobs such as updating dashboard, you can set a regular schedule
#schedule:
# - cron: "0 8 * * *"

jobs:
container-workflow-template:
runs-on: ubuntu-latest # Run on GitHub Actions runner
#runs-on: [self-hosted, linux, x64, onprem-aegypti] # Run the workflow on EHA aegypti runner (permissions required)
#runs-on: [self-hosted, linux, x64, onprem-prospero] # Run the workflow on EHA prospero runner (permissions required)
container:
image: rocker/verse:4.2.1
image: rocker/r-ver:4.2.1

steps:

steps:
# update to: git config --global --add safe.directory /__w/your-repo/your-repo
- name: update permissions for container based workflows
run: git config --global --add safe.directory /__w/container-template/container-template

- uses: actions/checkout@v2

- name: Install system dependencies
run: |
apt-get update && apt-get install -y --no-install-recommends \
libcurl4-openssl-dev \
libssl-dev
- name: Install packages from renv.lock (with cache)
if: ${{ !env.ACT }} ## Doesn't work locally with ACT
uses: r-lib/actions/setup-renv@v2
Expand All @@ -43,14 +43,14 @@ jobs:
run: |
renv::restore()
shell: Rscript {0}

- name: Run targets workflow
run: |
targets::tar_make()
shell: Rscript {0}

- name: On failure, launch a temporary interactive debugging session
uses: mxschmitt/action-tmate@v3
if: ${{ failure() }}
timeout-minutes: 15

Loading

0 comments on commit 20f511d

Please sign in to comment.