Skip to content

Commit 0c0b2f5

Browse files
committed
config
1 parent 22cc672 commit 0c0b2f5

3 files changed

Lines changed: 166 additions & 102 deletions

File tree

R/gdoc2qmd.R

Lines changed: 62 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -114,35 +114,70 @@ gdoc2qmd <- function(file
114114
} else {.}
115115
}
116116

117-
tab <- txt %>%
118-
dplyr::filter(grepl("^\\|", .data$value) | grepl("#tbl", .data$value)) %>%
119-
dplyr::ungroup() %>%
120-
dplyr::mutate(group = case_when(
121-
grepl("#tbl", .data$value) ~ .data$name
122-
)) %>%
123-
tidyr::fill(., .data$group, .direction = fill_table) %>%
124-
# dplyr::mutate(group = case_when(
125-
# is.na(.data$group) ~ 1
126-
# , .default = .data$group
127-
# )) %>%
128-
split(.$group) %>%
129-
# purrr::map_dfr(~ slice(.data = ., c(n(), 1:(n()-1)))) %>%
130-
# split(.$group) %>%
131-
purrr::map_dfr(~ bind_rows(tibble(name = NA, value = NA), .x)) %>%
132-
dplyr::mutate(.data = ., across(.data$value, ~ ifelse(is.na(.), "\\newpage", .)))
117+
# tab <- txt %>%
118+
# dplyr::filter(grepl("^\\|", .data$value) | grepl("#tbl", .data$value)) %>%
119+
# dplyr::ungroup() %>%
120+
# dplyr::mutate(group = case_when(
121+
# grepl("#tbl", .data$value) ~ .data$name
122+
# )) %>%
123+
# tidyr::fill(., .data$group, .direction = fill_table) %>%
124+
# # dplyr::mutate(group = case_when(
125+
# # is.na(.data$group) ~ 1
126+
# # , .default = .data$group
127+
# # )) %>%
128+
# split(.$group) %>%
129+
# # purrr::map_dfr(~ slice(.data = ., c(n(), 1:(n()-1)))) %>%
130+
# # split(.$group) %>%
131+
# purrr::map_dfr(~ bind_rows(tibble(name = NA, value = NA), .x)) %>%
132+
# dplyr::mutate(.data = ., across(.data$value, ~ ifelse(is.na(.), "\\newpage", .)))
133+
#
134+
# tabx <- tab %>%
135+
# dplyr::rowwise() %>%
136+
# dplyr::mutate(across(.data$value, ~gsub("\\{#tbl:(.*)\\}", paste0("{#tbl:", .data$name ,"}"), .)))
137+
#
138+
# tablist <- tab %>%
139+
# dplyr::filter(!grepl("\\|", .data$value)) %>%
140+
# dplyr::mutate(value = case_when(
141+
# dplyr::row_number() == 1 ~ .data$value
142+
# , grepl("#tbl", .data$value) ~ .data$value
143+
# , TRUE ~ "\n\n"
144+
# ))
133145

134-
tabx <- tab %>%
135-
dplyr::rowwise() %>%
136-
dplyr::mutate(across(.data$value, ~gsub("\\{#tbl:(.*)\\}", paste0("{#tbl:", .data$name ,"}"), .)))
146+
if (any(grepl("^\\|", txt$value) | grepl("#tbl", txt$value))) {
147+
148+
tab <- txt %>%
149+
dplyr::filter(grepl("^\\|", value) | grepl("#tbl", value)) %>%
150+
dplyr::ungroup() %>%
151+
dplyr::mutate(group = case_when(
152+
grepl("#tbl", value) ~ name
153+
)) %>%
154+
tidyr::fill(group, .direction = fill_table) %>%
155+
split(.$group) %>%
156+
purrr::map_dfr(~ bind_rows(tibble(name = NA, value = NA), .x)) %>%
157+
dplyr::mutate(across(value, ~ ifelse(is.na(.), "\\newpage", .)))
158+
159+
tabx <- tab %>%
160+
dplyr::rowwise() %>%
161+
dplyr::mutate(value = gsub("\\{#tbl:(.*)\\}", paste0("{#tbl:", name ,"}"), value))
162+
163+
tablist <- tab %>%
164+
dplyr::filter(!grepl("\\|", value)) %>%
165+
dplyr::mutate(value = case_when(
166+
dplyr::row_number() == 1 ~ value,
167+
grepl("#tbl", value) ~ value,
168+
TRUE ~ "\n\n"
169+
))
170+
171+
} else {
172+
173+
tab <- tibble()
174+
175+
tabx <- tibble()
176+
177+
tablist <- tibble()
178+
179+
}
137180

138-
tablist <- tab %>%
139-
dplyr::filter(!grepl("\\|", .data$value)) %>%
140-
dplyr::mutate(value = case_when(
141-
dplyr::row_number() == 1 ~ .data$value
142-
, grepl("#tbl", .data$value) ~ .data$value
143-
, TRUE ~ "\n\n"
144-
))
145-
146181
# -------------------------------------------------------------------------
147182

148183
manuscript <- if(type == "full") {

R/utils.R

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,50 @@ tarpuy_full <- function() {
3232

3333
}
3434

35-
anova_table <- function(model) {
36-
37-
model %>%
38-
rownames_to_column("Factor") %>%
39-
mutate(Sig = case_when(
40-
`Pr(>F)` <= 0.001 ~ "***"
41-
, `Pr(>F)` <= 0.01 ~ "**"
42-
, `Pr(>F)` <= 0.05 ~ "*"
43-
, `Pr(>F)` > 0.05 ~ "ns"
44-
)) %>%
45-
mutate(across(everything(), as.factor)) %>%
46-
tibble() %>%
47-
tibble::add_row(Factor = "---") %>%
48-
tibble::add_row(Factor = "Significance:"
49-
, `Sum Sq` = "0.001 ***"
50-
, `Mean Sq` = "0.01 **"
51-
, `F value` = "0.05 *"
35+
anova_table <- function(model, digits = 4) {
36+
37+
df <- as.data.frame(model) %>%
38+
tibble::rownames_to_column("Factor")
39+
40+
# Detectar nombre de la columna de p-valor
41+
p_col <- dplyr::case_when(
42+
"Pr(>F)" %in% names(df) ~ "Pr(>F)",
43+
"Pr(>Chisq)" %in% names(df) ~ "Pr(>Chisq)",
44+
TRUE ~ NA_character_
45+
)
46+
47+
if (is.na(p_col)) stop("No p-value column found: expected 'Pr(>F)' or 'Pr(>Chisq)'.")
48+
49+
# Formato de p-valores: notación científica si son muy pequeños
50+
df[[p_col]] <- ifelse(
51+
df[[p_col]] < 0.0001,
52+
formatC(df[[p_col]], format = "e", digits = digits),
53+
formatC(df[[p_col]], format = "f", digits = digits)
54+
)
55+
56+
# Añadir columna de significancia
57+
df <- df %>%
58+
dplyr::mutate(
59+
Sig = dplyr::case_when(
60+
as.numeric(.data[[p_col]]) <= 0.001 ~ "***",
61+
as.numeric(.data[[p_col]]) <= 0.01 ~ "**",
62+
as.numeric(.data[[p_col]]) <= 0.05 ~ "*",
63+
TRUE ~ "ns"
64+
)
5265
)
66+
67+
# Convertir columnas a texto
68+
df <- df %>% dplyr::mutate(across(everything(), as.character))
69+
70+
# Agregar leyenda
71+
df <- df %>%
72+
tibble::add_row(Factor = "---") %>%
73+
tibble::add_row(
74+
Factor = "Significance:",
75+
!!names(df)[2] := "0.001 ***",
76+
!!names(df)[3] := "0.01 **",
77+
!!p_col := "0.05 *"
78+
)
79+
80+
return(df)
5381
}

pkgdown/favicon/setup.r

Lines changed: 59 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,84 +2,85 @@
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

5945
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
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

Comments
 (0)