|
1 | 1 | # ------------------------------------------------------------------------- |
2 | | -# R packages dependencies and configuration ------------------------------- |
| 2 | +# 📄 R packages dependencies and configuration ---------------------------- |
3 | 3 | # ------------------------------------------------------------------------- |
4 | | -#> author .: Flavio Lozano-Isla (linkedin.com/in/flozanoisla/) |
5 | | -#> date .: 2025-05-16 |
| 4 | +#> Author .: Flavio Lozano-Isla (linkedin.com/in/flozanoisla/) |
| 5 | +#> Date .: 2025-07-23 |
6 | 6 | # ------------------------------------------------------------------------- |
7 | 7 |
|
8 | | -#> source("https://inkaverse.com/setup.r") |
| 8 | +# Optional: external setup script |
| 9 | +# source("https://inkaverse.com/setup.r") |
9 | 10 |
|
10 | 11 | # ------------------------------------------------------------------------- |
11 | | -# Packages ---------------------------------------------------------------- |
| 12 | +# 📦 Package loading and installation ------------------------------------- |
12 | 13 | # ------------------------------------------------------------------------- |
13 | 14 |
|
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) ) { |
| 15 | +cran_packages <- c( |
| 16 | + "devtools", "tidyverse" |
| 17 | + , "lme4", "car", "emmeans", "multcomp" |
| 18 | + , "FactoMineR", "psych" |
| 19 | + , "inti", "huito" |
| 20 | + , "googlesheets4", "googledrive" |
| 21 | + , "knitr", "grid", "magick" |
| 22 | + , "RhpcBLASctl" |
| 23 | + , "sessioninfo" |
| 24 | +) |
| 25 | + |
| 26 | +load_or_install <- function(pkgs) { |
| 27 | + for (pkg in pkgs) { |
| 28 | + if (!requireNamespace(pkg, quietly = TRUE)) { |
37 | 29 | install.packages(pkg) |
38 | | - library(pkg, character.only = TRUE) |
39 | | - } |
| 30 | + } |
| 31 | + suppressPackageStartupMessages(library(pkg, character.only = TRUE)) |
40 | 32 | } |
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) |
| 33 | +} |
| 34 | + |
| 35 | +load_or_install(cran_packages) |
54 | 36 |
|
55 | 37 | # ------------------------------------------------------------------------- |
56 | | -# Knitr options ----------------------------------------------------------- |
| 38 | +# ⚙️ System and computation configuration ---------------------------------- |
57 | 39 | # ------------------------------------------------------------------------- |
58 | 40 |
|
59 | 41 | knitr::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 |
| 42 | + fig.align = "center", |
| 43 | + out.width = "98%", |
| 44 | + message = FALSE, |
| 45 | + warning = FALSE, |
| 46 | + collapse = TRUE |
66 | 47 | ) |
67 | 48 |
|
68 | | -# ------------------------------------------------------------------------- |
69 | | -# Compile options --------------------------------------------------------- |
70 | | -# ------------------------------------------------------------------------- |
71 | | - |
72 | 49 | 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 | | -) |
| 50 | + OutDec = ".", scipen = 99, |
| 51 | + knitr.kable.NA = "", |
| 52 | + knitr.table.format = "pipe", |
| 53 | + citr.use_betterbiblatex = FALSE |
| 54 | +) |
| 55 | + |
| 56 | +# CPU configuration |
| 57 | +total_cores <- parallel::detectCores(logical = TRUE) |
| 58 | +usable_cores <- max(1, floor(total_cores * 0.8)) |
| 59 | +RhpcBLASctl::blas_set_num_threads(usable_cores) |
79 | 60 |
|
80 | 61 | # ------------------------------------------------------------------------- |
81 | | -# Authorize googledrive & googlesheets ------------------------------------ |
| 62 | +# 🔐 Google authentication ------------------------------------------------ |
82 | 63 | # ------------------------------------------------------------------------- |
83 | 64 |
|
84 | 65 | googlesheets4::gs4_auth(TRUE) |
85 | 66 | googledrive::drive_auth(TRUE) |
| 67 | + |
| 68 | +# ------------------------------------------------------------------------- |
| 69 | +# 📋 Environment info ----------------------------------------------------- |
| 70 | +# ------------------------------------------------------------------------- |
| 71 | + |
| 72 | +# Mostrar ruta del proyecto y número de núcleos |
| 73 | +cat("Project directory: ", getwd(), "\n") |
| 74 | +cat("CPU cores detected: ", total_cores, "\n") |
| 75 | +cat("CPU cores in use: ", usable_cores, "\n") |
| 76 | + |
| 77 | +# Información de sesión |
| 78 | +sessioninfo::session_info() %>% print() |
| 79 | + |
| 80 | +# ------------------------------------------------------------------------- |
| 81 | +# 🧹 Clean up ------------------------------------------------------------- |
| 82 | +# ------------------------------------------------------------------------- |
| 83 | + |
| 84 | +rm(cran_packages, load_or_install, total_cores, usable_cores) |
0 commit comments