Skip to content

Commit

Permalink
Merge pull request #53 from pharmaverse/automated-renv-lock-propagati…
Browse files Browse the repository at this point in the history
…on@devel

Propagate renv.lock from pharmaverse/admiralci
  • Loading branch information
galachad authored Sep 6, 2023
2 parents 3955a17 + 19e43c2 commit d5aa097
Show file tree
Hide file tree
Showing 20 changed files with 1,049 additions and 244 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@
^vignettes/adxx\.Rmd$
^vignettes/pharmaversesdtm\.Rmd$
^data-raw$
^.devcontainer$
51 changes: 42 additions & 9 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
# Set renv profile base on R version.
if ((Sys.getenv("GITHUB_ACTIONS") == "") && (Sys.getenv("DOCKER_CONTAINER_CONTEXT") == "")) {
renv_profile <- paste(R.version$major, substr(R.version$minor, 1, 1), sep = ".")
if (file.exists("./renv/profile")) {
message("Using renv profile from `renv/profile` file.")
} else if (renv_profile %in% c("4.1", "4.2", "4.3")) {
message("Set renv profile to `", renv_profile, "`")
Sys.setenv("RENV_PROFILE" = renv_profile)
.get_dependencies <- function(project_dir) {

admdev_loc <- find.package("admiraldev", lib.loc = .libPaths(), quiet = TRUE)
adm_dev_suggests <- if(length(admdev_loc) != 0) {
renv:::renv_dependencies_discover_description(admdev_loc, fields = c("Depends", "Imports", "LinkingTo", "Suggests"))
} else {
data.frame(Packages = character(0))
}
suggests_packages <- renv:::renv_dependencies_discover_description(project_dir, fields = "Suggests")

packages <- names(
renv:::renv_package_dependencies(
unique(c(
project_dir,
adm_dev_suggests[["Package"]],
suggests_packages[["Package"]],
c("staged.dependencies", "renv", "styler")
))
)
)
packages[!(packages %in% c("admiral", "admiraldev", "admiralci", "admiral.test", "pharmaversesdtm", getwd()))]
}

options(renv.snapshot.filter = .get_dependencies)

.renv_profile <- paste(R.version$major, substr(R.version$minor, 1, 1), sep = ".")
if (!file.exists("./renv/profile")) {
if (.renv_profile %in% c("4.1", "4.2", "4.3")) {
message("Set renv profile to `", .renv_profile, "`")
Sys.setenv("RENV_PROFILE" = .renv_profile)
} else {
message("This repository do not contains the renv profile for your R version.")
}
source("renv/activate.R")
} else {
options(repos = c(CRAN = "https://cran.rstudio.com"))
message(
"Using renv profile from `renv/profile` file.\n",
"The `", readLines("./renv/profile"), "` profile will be used."
)
}

if (Sys.getenv("GITHUB_ACTIONS") != "") {
options(repos = c(CRAN = "https://packagemanager.posit.co/cran/latest"))
Sys.setenv("RENV_AUTOLOADER_ENABLED" = FALSE)
}
Sys.setenv("RENV_CONFIG_SANDBOX_ENABLED" = FALSE)
Sys.setenv("RENV_CONFIG_AUTO_SNAPSHOT" = FALSE)
source("renv/activate.R")
76 changes: 76 additions & 0 deletions .devcontainer/4.1/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
// https://containers.dev/implementors/json_reference/
"name": "Admiral R-4.1 (RStudio) container",
"image": "ghcr.io/pharmaverse/admiralci-4.1:latest",
// Install Dev Container Features. More info: https://containers.dev/features
"containerEnv": {
"ROOT": "true",
"PASSWORD": "rstudio",
"DISABLE_AUTH": "true",
"RENV_AUTOLOADER_ENABLED": "false"
},
"features": {
"ghcr.io/rocker-org/devcontainer-features/r-rig:1": {
"version": "none",
"vscodeRSupport": "full",
"installRadian": true,
"installVscDebugger": true
},
"ghcr.io/rocker-org/devcontainer-features/renv-cache:latest": {},
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": true,
"configureZshAsDefaultShell": false,
"installOhMyZsh": true,
"username": "rstudio",
"upgradePackages": false
},
"ghcr.io/mikaello/devcontainer-features/modern-shell-utils:1": {}
},
"init": true,
"overrideCommand": false,

"postCreateCommand": "bash ./.devcontainer/postCreateCommand.sh",

"postAttachCommand": "$BROWSER \"https://${CODESPACE_NAME}-8787.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}/\"",

"customizations": {
"vscode": {
"settings": {
"r.rterm.linux": "/usr/local/bin/radian",
"r.bracketedPaste": true,
"editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs": "active"
},
"extensions": [
"vsls-contrib.codetour",
"GitHub.copilot",
"GitHub.copilot-chat",
// R extensions
"ikuyadeu.r",
"REditorSupport.r-lsp",
// Extra extension
"streetsidesoftware.code-spell-checker",
"eamodio.gitlens",
"cweijan.vscode-office",
"donjayamanne.githistory",
"GitHub.vscode-github-actions",
"GitHub.vscode-pull-request-github",
"GitHub.remotehub",
"alefragnani.Bookmarks",
"vscode-icons-team.vscode-icons"
]
}
},

// RStudio ports
"forwardPorts": [8787],
"portsAttributes": {
"8787": {
"label": "Rstudio",
"requireLocalPort": true,
"onAutoForward": "openBrowser"
}
},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root
"remoteUser": "rstudio"
}
76 changes: 76 additions & 0 deletions .devcontainer/4.2/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
// https://containers.dev/implementors/json_reference/
"name": "Admiral R-4.2 (RStudio) container",
"image": "ghcr.io/pharmaverse/admiralci-4.2:latest",
// Install Dev Container Features. More info: https://containers.dev/features
"containerEnv": {
"ROOT": "true",
"PASSWORD": "rstudio",
"DISABLE_AUTH": "true",
"RENV_AUTOLOADER_ENABLED": "false"
},
"features": {
"ghcr.io/rocker-org/devcontainer-features/r-rig:1": {
"version": "none",
"vscodeRSupport": "full",
"installRadian": true,
"installVscDebugger": true
},
"ghcr.io/rocker-org/devcontainer-features/renv-cache:latest": {},
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": true,
"configureZshAsDefaultShell": false,
"installOhMyZsh": true,
"username": "rstudio",
"upgradePackages": false
},
"ghcr.io/mikaello/devcontainer-features/modern-shell-utils:1": {}
},
"init": true,
"overrideCommand": false,

"postCreateCommand": "bash ./.devcontainer/postCreateCommand.sh",

"postAttachCommand": "$BROWSER \"https://${CODESPACE_NAME}-8787.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}/\"",

"customizations": {
"vscode": {
"settings": {
"r.rterm.linux": "/usr/local/bin/radian",
"r.bracketedPaste": true,
"editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs": "active"
},
"extensions": [
"vsls-contrib.codetour",
"GitHub.copilot",
"GitHub.copilot-chat",
// R extensions
"ikuyadeu.r",
"REditorSupport.r-lsp",
// Extra extension
"streetsidesoftware.code-spell-checker",
"eamodio.gitlens",
"cweijan.vscode-office",
"donjayamanne.githistory",
"GitHub.vscode-github-actions",
"GitHub.vscode-pull-request-github",
"GitHub.remotehub",
"alefragnani.Bookmarks",
"vscode-icons-team.vscode-icons"
]
}
},

// RStudio ports
"forwardPorts": [8787],
"portsAttributes": {
"8787": {
"label": "Rstudio",
"requireLocalPort": true,
"onAutoForward": "openBrowser"
}
},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root
"remoteUser": "rstudio"
}
76 changes: 76 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
// https://containers.dev/implementors/json_reference/
"name": "Admiral R-4.3 (RStudio) container",
"image": "ghcr.io/pharmaverse/admiralci-4.3:latest",
// Install Dev Container Features. More info: https://containers.dev/features
"containerEnv": {
"ROOT": "true",
"PASSWORD": "rstudio",
"DISABLE_AUTH": "true",
"RENV_AUTOLOADER_ENABLED": "false"
},
"features": {
"ghcr.io/rocker-org/devcontainer-features/r-rig:1": {
"version": "none",
"vscodeRSupport": "full",
"installRadian": true,
"installVscDebugger": true
},
"ghcr.io/rocker-org/devcontainer-features/renv-cache:latest": {},
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": true,
"configureZshAsDefaultShell": false,
"installOhMyZsh": true,
"username": "rstudio",
"upgradePackages": false
},
"ghcr.io/mikaello/devcontainer-features/modern-shell-utils:1": {}
},
"init": true,
"overrideCommand": false,

"postCreateCommand": "bash ./.devcontainer/postCreateCommand.sh",

"postAttachCommand": "$BROWSER \"https://${CODESPACE_NAME}-8787.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}/\"",

"customizations": {
"vscode": {
"settings": {
"r.rterm.linux": "/usr/local/bin/radian",
"r.bracketedPaste": true,
"editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs": "active"
},
"extensions": [
"vsls-contrib.codetour",
"GitHub.copilot",
"GitHub.copilot-chat",
// R extensions
"ikuyadeu.r",
"REditorSupport.r-lsp",
// Extra extension
"streetsidesoftware.code-spell-checker",
"eamodio.gitlens",
"cweijan.vscode-office",
"donjayamanne.githistory",
"GitHub.vscode-github-actions",
"GitHub.vscode-pull-request-github",
"GitHub.remotehub",
"alefragnani.Bookmarks",
"vscode-icons-team.vscode-icons"
]
}
},

// RStudio ports
"forwardPorts": [8787],
"portsAttributes": {
"8787": {
"label": "Rstudio",
"requireLocalPort": true,
"onAutoForward": "openBrowser"
}
},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root
"remoteUser": "rstudio"
}
5 changes: 5 additions & 0 deletions .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

R -q -e 'renv::restore(lockfile = file.path("renv", "profiles", paste(R.version$major, substr(R.version$minor, 1, 1), sep = "."), "renv.lock")); staged.dependencies::install_deps(staged.dependencies::dependency_table(project = ".", verbose = 1), verbose = 1);'

jq --arg folder "$(pwd)/" '. + { "initial_working_directory": $folder }' .devcontainer/rstudio-prefs.json > ~/.config/rstudio/rstudio-prefs.json
8 changes: 8 additions & 0 deletions .devcontainer/rstudio-prefs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"save_workspace": "never",
"always_save_history": false,
"reuse_sessions_for_project_links": true,
"posix_terminal_shell": "bash",
"initial_working_directory": "/workspaces",
"show_hidden_files": true
}
Loading

0 comments on commit d5aa097

Please sign in to comment.