diff --git a/.Rbuildignore b/.Rbuildignore index b1cb9722..24e5e90a 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -3,6 +3,7 @@ ^.*\.Rproj$ ^\.Rproj\.user$ ^\.github$ +^\.devcontainer$ ^\.lycheeignore$ ^README\.Rmd$ ^_pkgdown\.yml$ diff --git a/.Rprofile b/.Rprofile index 4c653784..a94c4d6f 100644 --- a/.Rprofile +++ b/.Rprofile @@ -24,19 +24,21 @@ if (Sys.getenv("GITHUB_ACTIONS") != "") { Sys.setenv("RENV_CONFIG_SANDBOX_ENABLED" = FALSE) Sys.setenv("RENV_CONFIG_AUTO_SNAPSHOT" = FALSE) -.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) +if (!Sys.getenv("RENV_AUTOLOADER_ENABLED") %in% c("false", "FALSE")) { + .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.") + } } else { - message("This repository do not contains the renv profile for your R version.") + message( + "Using renv profile from `renv/profile` file.\n", + "The `", readLines("./renv/profile"), "` profile will be used." + ) } -} else { - message( - "Using renv profile from `renv/profile` file.\n", - "The `", readLines("./renv/profile"), "` profile will be used." - ) } source("renv/activate.R") diff --git a/.devcontainer/4.1/devcontainer.json b/.devcontainer/4.1/devcontainer.json new file mode 100644 index 00000000..e60b4fd9 --- /dev/null +++ b/.devcontainer/4.1/devcontainer.json @@ -0,0 +1,95 @@ +{ + // https://containers.dev/implementors/json_reference/ + "name": "sdtm.oak (RStudio) container", + "image": "ghcr.io/pharmaverse/sdtm.oak-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": { + "./ca-cert": {}, + "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": {} + }, + "overrideFeatureInstallOrder": [ + "./ca-cert", + "./arm64-repos", + "ghcr.io/devcontainers/features/common-utils", + "ghcr.io/rocker-org/devcontainer-features/renv-cache", + "ghcr.io/rocker-org/devcontainer-features/r-rig", + "ghcr.io/mikaello/devcontainer-features/modern-shell-utils" + ], + "init": true, + "overrideCommand": false, + + "postCreateCommand": "bash ./.devcontainer/postCreateCommand.sh", + + "postAttachCommand": "rstudio || true", + + "customizations": { + "codespaces": { + "repositories": { + "pharmaverse/mint": { + "permissions": "write-all" + }, + "pharmaverse/raw.synthetic.data": { + "permissions": "write-all" + } + } + }, + "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" +} diff --git a/.devcontainer/4.2/devcontainer.json b/.devcontainer/4.2/devcontainer.json new file mode 100644 index 00000000..c197bc1b --- /dev/null +++ b/.devcontainer/4.2/devcontainer.json @@ -0,0 +1,95 @@ +{ + // https://containers.dev/implementors/json_reference/ + "name": "sdtm.oak R-4.2 (RStudio) container", + "image": "ghcr.io/pharmaverse/sdtm.oak-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": { + "./ca-cert": {}, + "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": {} + }, + "overrideFeatureInstallOrder": [ + "./ca-cert", + "./arm64-repos", + "ghcr.io/devcontainers/features/common-utils", + "ghcr.io/rocker-org/devcontainer-features/renv-cache", + "ghcr.io/rocker-org/devcontainer-features/r-rig", + "ghcr.io/mikaello/devcontainer-features/modern-shell-utils" + ], + "init": true, + "overrideCommand": false, + + "postCreateCommand": "bash ./.devcontainer/postCreateCommand.sh", + + "postAttachCommand": "rstudio || true", + + "customizations": { + "codespaces": { + "repositories": { + "pharmaverse/mint": { + "permissions": "write-all" + }, + "pharmaverse/raw.synthetic.data": { + "permissions": "write-all" + } + } + }, + "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" +} diff --git a/.devcontainer/arm64-repos/devcontainer-feature.json b/.devcontainer/arm64-repos/devcontainer-feature.json new file mode 100644 index 00000000..8b9e2b99 --- /dev/null +++ b/.devcontainer/arm64-repos/devcontainer-feature.json @@ -0,0 +1,7 @@ +{ + "name": "arm64 repos", + "id": "arm64-repos", + "version": "0.1.0", + "description": "Fix repos for arm64.", + "options": {} +} \ No newline at end of file diff --git a/.devcontainer/arm64-repos/install.sh b/.devcontainer/arm64-repos/install.sh new file mode 100644 index 00000000..92f74c1e --- /dev/null +++ b/.devcontainer/arm64-repos/install.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -e + +ARCH=$(uname -m) + +## source install if using RSPM and arm64 image +if [ "$ARCH" = "aarch64" ]; then + +CRAN="https://cloud.r-project.org" + +## Add a default CRAN mirror +echo "options(repos = c(CRAN = '${CRAN}'), download.file.method = 'libcurl')" >"${R_HOME}/etc/Rprofile.site" + +## Set HTTPUserAgent for RSPM (https://github.com/rocker-org/rocker/issues/400) +cat <>"${R_HOME}/etc/Rprofile.site" +# https://docs.rstudio.com/rspm/admin/serving-binaries/#binaries-r-configuration-linux +options(HTTPUserAgent = sprintf("R/%s R (%s)", getRversion(), paste(getRversion(), R.version["platform"], R.version["arch"], R.version["os"]))) +EOF + +fi + diff --git a/.devcontainer/ca-cert/.gitignore b/.devcontainer/ca-cert/.gitignore new file mode 100644 index 00000000..ee0cb61c --- /dev/null +++ b/.devcontainer/ca-cert/.gitignore @@ -0,0 +1 @@ +*.crt \ No newline at end of file diff --git a/.devcontainer/ca-cert/devcontainer-feature.json b/.devcontainer/ca-cert/devcontainer-feature.json new file mode 100644 index 00000000..7aea7af9 --- /dev/null +++ b/.devcontainer/ca-cert/devcontainer-feature.json @@ -0,0 +1,7 @@ +{ + "name": "CA cert", + "id": "ca-cert", + "version": "0.1.0", + "description": "Copy CA cert into the container.", + "options": {} +} \ No newline at end of file diff --git a/.devcontainer/ca-cert/install.sh b/.devcontainer/ca-cert/install.sh new file mode 100644 index 00000000..6064b36b --- /dev/null +++ b/.devcontainer/ca-cert/install.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +set -e + +# Copy CA certificate to `/etc/ssl/cert` +if ls *.crt 1> /dev/null 2>&1; then + sudo cp *.crt /usr/local/share/ca-certificates + sudo update-ca-certificates +fi + +echo "Done!" \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..5b8de048 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,96 @@ +{ + // https://containers.dev/implementors/json_reference/ + "name": "sdtm.oak R-4.3 (RStudio) container", + "image": "ghcr.io/pharmaverse/sdtm.oak-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": { + "./ca-cert": {}, + "./arm64-repos": {}, + "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": {} + }, + "overrideFeatureInstallOrder": [ + "./ca-cert", + "./arm64-repos", + "ghcr.io/devcontainers/features/common-utils", + "ghcr.io/rocker-org/devcontainer-features/renv-cache", + "ghcr.io/rocker-org/devcontainer-features/r-rig", + "ghcr.io/mikaello/devcontainer-features/modern-shell-utils" + ], + "init": true, + "overrideCommand": false, + + "postCreateCommand": "bash ./.devcontainer/postCreateCommand.sh", + + "postAttachCommand": "rstudio || true", + + "customizations": { + "codespaces": { + "repositories": { + "pharmaverse/mint": { + "permissions": "read-all" + }, + "pharmaverse/raw.synthetic.data": { + "permissions": "read-all" + } + } + }, + "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" +} diff --git a/.devcontainer/postCreateCommand.sh b/.devcontainer/postCreateCommand.sh new file mode 100644 index 00000000..8dfe4e23 --- /dev/null +++ b/.devcontainer/postCreateCommand.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# move script rstudio into /usr/bin +sudo cp "$(pwd)/.devcontainer/rstudio.sh" /usr/bin/rstudio +sudo chmod +x /usr/bin/rstudio + +# Restore renv and install staged dependencies +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);' + +# Define rstudio default working directory +jq --arg folder "$(pwd)/" '. + { "initial_working_directory": $folder }' .devcontainer/rstudio-prefs.json > ~/.config/rstudio/rstudio-prefs.json diff --git a/.devcontainer/rstudio-prefs.json b/.devcontainer/rstudio-prefs.json new file mode 100644 index 00000000..2d5cce84 --- /dev/null +++ b/.devcontainer/rstudio-prefs.json @@ -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 +} diff --git a/.devcontainer/rstudio.sh b/.devcontainer/rstudio.sh new file mode 100644 index 00000000..053a247b --- /dev/null +++ b/.devcontainer/rstudio.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +$BROWSER "https://${CODESPACE_NAME}-8787.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}" + +exit 1