22# R packages dependencies and configuration -------------------------------
33# -------------------------------------------------------------------------
44# > author .: Flavio Lozano-Isla (linkedin.com/in/flozanoisla/)
5- # > date .: 2025-05-16
5+ # > date .: 2025-07-23
66# -------------------------------------------------------------------------
77
88# > source("https://inkaverse.com/setup.r")
99
1010# -------------------------------------------------------------------------
11- # Packages --------------------------- -------------------------------------
11+ # 📦 Package loading and installation -------------------------------------
1212# -------------------------------------------------------------------------
1313
14- cran <- c(
15- " devtools" # Developer tools
16- , " inti" # Tools and Statistical Procedures in Plant Science
17- , " FactoMineR" # Multivariate data analysis
18- , " psych" # Correlation plot
19- , " lme4"
20- , " car"
21- , " emmeans"
22- , " multcomp"
23- , " huito" # label design
24- , " grid" # Import images as R object
25- , " googlesheets4" # Read/write google sheets docs
26- , " googledrive" # Download/Upload files from googledrive
27- , " knitr" # Write docs using R
28- , " tidyverse" # Data manipulation
29- )
30-
31- # git <- c("crsh/citr") # Use zotero for docs citations
32-
33- suppressPackageStartupMessages({
34-
35- for (pkg in cran ) {
36- if ( ! require(pkg , character.only = TRUE ) ) {
14+ cran_packages <- c(
15+ " devtools" , " inti" , " FactoMineR" , " psych" , " lme4" , " car" , " emmeans" ,
16+ " multcomp" , " huito" , " grid" , " googlesheets4" , " googledrive" ,
17+ " knitr" , " tidyverse" , " RhpcBLASctl" , " sessioninfo" , " cli"
18+ )
19+
20+ load_or_install <- function (pkgs ) {
21+ for (pkg in pkgs ) {
22+ if (! requireNamespace(pkg , quietly = TRUE )) {
3723 install.packages(pkg )
38- library( pkg , character.only = TRUE )
39- }
24+ }
25+ suppressPackageStartupMessages(library( pkg , character.only = TRUE ))
4026 }
41-
42- # for (pkg in git) {
43- # if( !require(sub(".*/", "", pkg), character.only = T) ) {
44- # devtools::install_github(pkg, upgrade = T)
45- # library(sub(".*/", "", pkg), character.only = T)
46- # }
47- # }
48-
49- })
50-
51- remove( cran
52- # , git
53- , pkg )
27+ }
28+
29+ load_or_install( cran_packages )
30+
31+ # Optional GitHub packages
32+ # git_packages <- c("crsh/citr")
33+ # for (repo in git_packages) {
34+ # pkg <- sub(".*/", "", repo)
35+ # if (!requireNamespace(pkg, quietly = TRUE)) {
36+ # devtools::install_github(repo, upgrade = TRUE)
37+ # }
38+ # suppressPackageStartupMessages(library(pkg, character.only = TRUE))
39+ # }
5440
5541# -------------------------------------------------------------------------
56- # Knitr options ------------------------- ----------------------------------
42+ # ⚙️ System and computation configuration ----------------------------------
5743# -------------------------------------------------------------------------
5844
5945knitr :: opts_chunk $ set(
60- fig.align = " center" # Center images in the export file
61- , out.width = " 98%" # Figure width in html
62- # , echo = FALSE # Avoid print code in the export file
63- , message = FALSE # Avoid print messages in the export file
64- , warning = FALSE # Avoid print warnings in the export file
65- , collapse = TRUE # Collapse text output into source blocks
46+ fig.align = " center" ,
47+ out.width = " 98%" ,
48+ message = FALSE ,
49+ warning = FALSE ,
50+ collapse = TRUE
51+ )
52+
53+ options(
54+ OutDec = " ." , scipen = 99 ,
55+ knitr.kable.NA = " " ,
56+ knitr.table.format = " pipe" ,
57+ citr.use_betterbiblatex = FALSE
6658)
6759
60+ total_cores <- parallel :: detectCores(logical = TRUE )
61+ usable_cores <- max(1 , floor(total_cores * 0.8 ))
62+ RhpcBLASctl :: blas_set_num_threads(usable_cores )
63+
64+ cli :: cli_alert_info(" 📁 Project directory: {getwd()}" )
65+ cli :: cli_alert_info(" 🧠 Total CPU cores detected: {total_cores}" )
66+ cli :: cli_alert_info(" 🚀 BLAS threads configured to: {RhpcBLASctl::blas_get_num_threads()}" )
67+
6868# -------------------------------------------------------------------------
69- # Compile options --------- ------------------------------------------------
69+ # 🔐 Google authentication ------------------------------------------------
7070# -------------------------------------------------------------------------
7171
72- options(
73- OutDec = " ." # Use "." instead of "," in the decimal values
74- , scipen = 99 # Avoid use "6e-04"
75- , knitr.kable.NA = " " # NA values will appear as empty cell
76- , knitr.table.format = " pipe" # Format for export tables
77- , citr.use_betterbiblatex = FALSE # For zotero addin
78- )
72+ googlesheets4 :: gs4_auth(cache = " .secrets" , use_oob = TRUE )
73+ googledrive :: drive_auth(cache = " .secrets" , use_oob = TRUE )
74+
75+ # -------------------------------------------------------------------------
76+ # 📋 Environment info -----------------------------------------------------
77+ # -------------------------------------------------------------------------
78+
79+ sessioninfo :: session_info()
7980
8081# -------------------------------------------------------------------------
81- # Authorize googledrive & googlesheets ------------------------------------
82+ # 🧹 Clean up ------------------------- ------------------------------------
8283# -------------------------------------------------------------------------
8384
84- googlesheets4 :: gs4_auth( TRUE )
85- googledrive :: drive_auth( TRUE )
85+ rm( cran_packages , load_or_install , total_cores , usable_cores )
86+ # rm(git_packages) # if defined
0 commit comments