├── .gitignore ├── README.md ├── hideslide.lua ├── images ├── .gitignore ├── Fig1.jpg ├── Fig3.png ├── R_Word_comm.png ├── ReproducibleMatrix.jpg ├── Rlogo.png ├── Rmd-exp.png ├── Rmd.png ├── Word-sentence.png ├── Word.jpg ├── antica.png ├── besguide.jpg ├── citations-Rstudio14.png ├── citr.png ├── codecheck.png ├── copy-paste.png ├── csl.png ├── datos-codigo-texto.jpg ├── drake-plan.png ├── git.png ├── good-enough.png ├── goodenough.png ├── gramr.jpg ├── holepunch.png ├── horrormovie.png ├── liftr.png ├── pnas.png ├── puzzle.jpeg ├── rcrossref-doi.png ├── rcrossref-metadata.png ├── rmdlogo.png ├── rrtools-addin.png ├── sotobosque.png ├── tabla-traducida.png ├── travis.PNG ├── turingway.jpg ├── visualRmd.png ├── workflowr.png └── wtf.png ├── slides.Rmd ├── slides.pdf └── writing-reproducible-manuscripts.Rproj /.gitignore: -------------------------------------------------------------------------------- 1 | # History files 2 | .Rhistory 3 | .Rapp.history 4 | # Session Data files 5 | .RData 6 | # User-specific files 7 | .Ruserdata 8 | # Example code in package build process 9 | *-Ex.R 10 | # Output files from R CMD build 11 | /*.tar.gz 12 | # Output files from R CMD check 13 | /*.Rcheck/ 14 | # RStudio files 15 | .Rproj.user/ 16 | # produced vignettes 17 | vignettes/*.html 18 | vignettes/*.pdf 19 | # OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 20 | .httr-oauth 21 | # knitr and R markdown default cache directories 22 | *_cache/ 23 | /cache/ 24 | # Temporary files created by R markdown 25 | *.utf8.md 26 | *.knit.md 27 | # R Environment Variables 28 | .Renviron 29 | .fertile_log.csv 30 | deps.yaml 31 | mypaper.Rmd 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # writing-reproducible-manuscripts 2 | Talk on writing reproducible manuscripts 3 | -------------------------------------------------------------------------------- /hideslide.lua: -------------------------------------------------------------------------------- 1 | function Div(el) 2 | if el.classes[1] == 'hide' then 3 | return {} 4 | else 5 | return el 6 | end 7 | end 8 | 9 | -- https://stackoverflow.com/a/58679929 10 | -------------------------------------------------------------------------------- /images/.gitignore: -------------------------------------------------------------------------------- 1 | Rmd-exp.odg 2 | R-Word.odg 3 | copy-paste-table.gif 4 | -------------------------------------------------------------------------------- /images/Fig1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/Fig1.jpg -------------------------------------------------------------------------------- /images/Fig3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/Fig3.png -------------------------------------------------------------------------------- /images/R_Word_comm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/R_Word_comm.png -------------------------------------------------------------------------------- /images/ReproducibleMatrix.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/ReproducibleMatrix.jpg -------------------------------------------------------------------------------- /images/Rlogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/Rlogo.png -------------------------------------------------------------------------------- /images/Rmd-exp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/Rmd-exp.png -------------------------------------------------------------------------------- /images/Rmd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/Rmd.png -------------------------------------------------------------------------------- /images/Word-sentence.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/Word-sentence.png -------------------------------------------------------------------------------- /images/Word.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/Word.jpg -------------------------------------------------------------------------------- /images/antica.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/antica.png -------------------------------------------------------------------------------- /images/besguide.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/besguide.jpg -------------------------------------------------------------------------------- /images/citations-Rstudio14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/citations-Rstudio14.png -------------------------------------------------------------------------------- /images/citr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/citr.png -------------------------------------------------------------------------------- /images/codecheck.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/codecheck.png -------------------------------------------------------------------------------- /images/copy-paste.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/copy-paste.png -------------------------------------------------------------------------------- /images/csl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/csl.png -------------------------------------------------------------------------------- /images/datos-codigo-texto.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/datos-codigo-texto.jpg -------------------------------------------------------------------------------- /images/drake-plan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/drake-plan.png -------------------------------------------------------------------------------- /images/git.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/git.png -------------------------------------------------------------------------------- /images/good-enough.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/good-enough.png -------------------------------------------------------------------------------- /images/goodenough.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/goodenough.png -------------------------------------------------------------------------------- /images/gramr.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/gramr.jpg -------------------------------------------------------------------------------- /images/holepunch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/holepunch.png -------------------------------------------------------------------------------- /images/horrormovie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/horrormovie.png -------------------------------------------------------------------------------- /images/liftr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/liftr.png -------------------------------------------------------------------------------- /images/pnas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/pnas.png -------------------------------------------------------------------------------- /images/puzzle.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/puzzle.jpeg -------------------------------------------------------------------------------- /images/rcrossref-doi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/rcrossref-doi.png -------------------------------------------------------------------------------- /images/rcrossref-metadata.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/rcrossref-metadata.png -------------------------------------------------------------------------------- /images/rmdlogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/rmdlogo.png -------------------------------------------------------------------------------- /images/rrtools-addin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/rrtools-addin.png -------------------------------------------------------------------------------- /images/sotobosque.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/sotobosque.png -------------------------------------------------------------------------------- /images/tabla-traducida.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/tabla-traducida.png -------------------------------------------------------------------------------- /images/travis.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/travis.PNG -------------------------------------------------------------------------------- /images/turingway.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/turingway.jpg -------------------------------------------------------------------------------- /images/visualRmd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/visualRmd.png -------------------------------------------------------------------------------- /images/workflowr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/workflowr.png -------------------------------------------------------------------------------- /images/wtf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/images/wtf.png -------------------------------------------------------------------------------- /slides.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: Cómo escribir manuscritos reproducibles 3 | subtitle: \small (algunas ideas y herramientas) 4 | author: Francisco Rodríguez-Sánchez 5 | date: '@frod_san' 6 | institute: https://frodriguezsanchez.net 7 | output: 8 | binb::metropolis: 9 | keep_tex: no 10 | pandoc_args: ["--lua-filter=hideslide.lua"] 11 | fontsize: 12pt 12 | urlcolor: blue 13 | header-includes: 14 | \definecolor{shadecolor}{RGB}{230,230,230} 15 | 16 | --- 17 | 18 | ```{r setup, include=FALSE} 19 | library("knitr") 20 | knitr::opts_chunk$set(echo = FALSE, cache = TRUE, background = "red", 21 | out.width = '3in', out.height = '2in', fig.align = 'center') 22 | ``` 23 | 24 | 25 | 26 | 27 | ## ¿Qué es un manuscrito reproducible? 28 | 29 | ```{r out.width = '3in', out.height = '1.3in'} 30 | include_graphics("images/datos-codigo-texto.jpg") 31 | ``` 32 | 33 | DATOS + CÓDIGO 34 | 35 | - **trazar** proceso de análisis 36 | 37 | - **reproducir** (regenerar) todos los resultados 38 | 39 | 40 | ::: hide ::: 41 | ## La ciencia debe ser reproducible 42 | 43 | ```{r out.width = '4in', out.height = '2.2in'} 44 | include_graphics("images/tabla-traducida.png") 45 | ``` 46 | 47 | \raggedright 48 | \footnotesize [The Turing Way](https://the-turing-way.netlify.app/welcome) 49 | \raggedleft 50 | 51 | 52 | 53 | ## Reproducibilidad: buena para ti, buena para todos 54 | 55 | + Transparencia 56 | + Trazabilidad 57 | + Automatización 58 | + Calidad (- errores) 59 | + Impacto (citas, reconocimiento) 60 | + Reutilización (datos y código) 61 | + Archivo permanente 62 | 63 | ::: 64 | 65 | 66 | 67 | --- 68 | 69 | \huge 70 | 71 | La inmensa mayoría 72 | 73 | de artículos científicos 74 | 75 | **NO son reproducibles** 76 | 77 | \normalsize 78 | 79 | 80 | ## La reproducibilidad es un gradiente 81 | 82 | ```{r out.width = '4.5in', out.height = '1.7in'} 83 | include_graphics("images/Fig1.jpg") 84 | ``` 85 | 86 | \raggedright 87 | \tiny [Rodríguez-Sánchez et al. 2016](https://www.revistaecosistemas.net/index.php/ecosistemas/article/view/1178) (modif. [Peng 2011](https://doi.org/10.1126/science.1213847)) 88 | \raggedleft 89 | 90 | # Reproducibilidad básica 91 | 92 | ## Reproducibilidad básica 93 | 94 | - **MANUSCRITO** (Texto + Tablas + Figuras) 95 | 96 | - **DATOS** (archivo permanente) 97 | 98 | - **CÓDIGO** (archivo permanente) 99 | 100 | \vspace{10mm} 101 | 102 | \footnotesize 103 | 104 | *Archivo permanente*: 105 | 106 | - Zenodo, Dryad, OSF, Figshare, Data Paper... 107 | 108 | - NO GitHub, web... 109 | 110 | \normalsize 111 | 112 | 113 | ## Cómo compartir datos 114 | 115 | >- Formato **abierto** (csv, txt) 116 | 117 | >- Datos brutos + código depuración 118 | 119 | >- **README** (who, what, when, where, why, how) 120 | 121 | >- **Descripción variables** (`dataspice`, `codebook`) 122 | 123 | >- **Licencia** (CC0, CC-BY, ODbL) 124 | 125 | >- **Cita** (DOI) 126 | 127 | >- **Metadatos** estandarizados (JSON, XML) 128 | 129 | \raggedright 130 | \tiny [Tierney & Ram 2020](https://arxiv.org/abs/2002.11626) 131 | \raggedleft 132 | 133 | 134 | ## Cómo compartir código 135 | 136 | >- Scripts **texto** (`.R`) 137 | 138 | >- **Archivo permanente** (ej. Zenodo) con DOI (citable) 139 | 140 | >- [Licencia](https://www.software.ac.uk/resources/guides/adopting-open-source-licence) 141 | 142 | >- **README** (incluir `sessionInfo()`) 143 | 144 | \raggedright 145 | \tiny [Eglen et al 2016](https://doi.org/10.1038/nn.4550) 146 | \raggedleft 147 | 148 | 149 | ## `sessionInfo()`: registro del entorno computacional 150 | 151 | \tiny 152 | 153 | ```{r echo=TRUE} 154 | sessionInfo() 155 | ``` 156 | 157 | \normalsize 158 | 159 | 160 | 161 | 162 | ## Cómo escribir código más reproducible 163 | 164 | [BES guide to reproducible code](https://www.britishecologicalsociety.org/wp-content/uploads/2019/06/BES-Guide-Reproducible-Code-2019.pdf) 165 | 166 | ```{r out.width = '1.8in', out.height = '2.5in'} 167 | include_graphics("images/besguide.jpg") 168 | ``` 169 | 170 | 171 | ## Cómo escribir código más reproducible 172 | 173 | [Turing Way](https://the-turing-way.netlify.app) 174 | 175 | ```{r out.width = '2.5in', out.height = '1.7in'} 176 | include_graphics("images/turingway.jpg") 177 | ``` 178 | 179 | 180 | 181 | ## Cómo escribir código más reproducible 182 | 183 | ```{r out.width = '4in', out.height = '1.2in'} 184 | include_graphics("images/good-enough.png") 185 | ``` 186 | 187 | \raggedright 188 | \tiny [Wilson et al 2017](https://doi.org/10.1371/journal.pcbi.1005510) 189 | \raggedleft 190 | 191 | 192 | ## Cómo escribir código más reproducible 193 | 194 | https://rstats.wtf 195 | 196 | ```{r out.width = '4in', out.height = '1in'} 197 | include_graphics("images/wtf.png") 198 | ``` 199 | 200 | 201 | ## Cómo escribir código más reproducible 202 | 203 | Control de versiones (`git`) 204 | 205 | ```{r out.width = '3.5in', out.height = '1.7in'} 206 | include_graphics("images/git.png") 207 | ``` 208 | 209 | \raggedright 210 | \tiny [R. Fitzjohn](https://github.com/richfitz/reproducibility-2014) 211 | \raggedleft 212 | 213 | 214 | 215 | 216 | 217 | ## Cómo escribir código más reproducible 218 | 219 | `fertile`: creating optimal conditions for reproducibility 220 | 221 | ```{r echo = TRUE, eval=FALSE} 222 | library("fertile") 223 | setwd("C:/Users/FRS") 224 | ``` 225 | 226 | *Error: setwd() is likely to break reproducibility. Use here::here() instead.* 227 | 228 | \vspace{5mm} 229 | 230 | \scriptsize https://github.com/baumer-lab/fertile 231 | 232 | 233 | 234 | 235 | ## Codecheck: ¿es tu artículo reproducible? 236 | 237 | https://codecheck.org.uk 238 | 239 | ```{r out.width = '2.5in', out.height = '1.3in'} 240 | include_graphics("images/codecheck.png") 241 | ``` 242 | 243 | 244 | 245 | ::: hide ::: 246 | ## Reproducibilidad básica 247 | 248 | \large 249 | 250 | - **MANUSCRITO** (texto + tablas + figuras) 251 | 252 | - **DATOS** (archivo permanente) 253 | 254 | - **CÓDIGO** (archivo permanente) 255 | 256 | \normalsize 257 | 258 | 259 | --- 260 | 261 | \huge 262 | 263 | La inmensa mayoría 264 | 265 | de artículos científicos 266 | 267 | **NO son reproducibles** 268 | 269 | \normalsize 270 | 271 | 272 | ## El código existe, pero no se comparte 273 | 274 | ```{r out.width = '2in', out.height = '2.5in'} 275 | include_graphics("images/antica.png") 276 | ``` 277 | 278 | \raggedright 279 | \tiny [Antica et al. 2020](https://doi.org/10.1371/journal.pbio.3000763) 280 | \raggedleft 281 | 282 | --- 283 | 284 | \huge 285 | 286 | Las barreras 287 | 288 | NO son técnicas 289 | 290 | \normalsize 291 | 292 | 293 | 294 | 295 | 296 | ## Venzamos las barreras sociológicas 297 | 298 | ```{r out.width = '3in', out.height = '1in'} 299 | include_graphics("images/goodenough.png") 300 | ``` 301 | 302 | \raggedright 303 | \tiny [Barnes 2010](https://doi.org/10.1038/467753a) 304 | \raggedleft 305 | 306 | \normalsize 307 | 308 | - Comunidad debe ser constructiva (no *shaming*) 309 | 310 | - 'Ugly code better than no code' 311 | 312 | ::: 313 | 314 | # 'Literate programming' con Rmarkdown 315 | 316 | 317 | 318 | ## Desconexión de código y manuscrito genera problemas 319 | 320 | ```{r out.width = '3in', out.height = '1in'} 321 | include_graphics("images/R_Word_comm.png") 322 | ``` 323 | 324 | 325 | 'Transcribing numbers **from stats software to ms by hand** 326 | 327 | was the largest source of errors' 328 | 329 | \tiny ([Eubank 2016](https://doi.org/10.1017/S1049096516000196)) 330 | 331 | 332 | 333 | 334 | 335 | ## Había un dato erróneo...\newline¿Puedes repetir el análisis y actualizar el ms? 336 | 337 | Copiar y pegar... 338 | 339 | ```{r out.width = '3in', out.height = '0.8in'} 340 | #include_graphics("images/copy-paste-table.gif") 341 | include_graphics("images/copy-paste.png") 342 | ``` 343 | 344 | 345 | ::: hide ::: 346 | ## Las ventajas de la reproducibilidad en <2 minutos 347 | 348 | ```{r out.width = '3.5in', out.height = '2.2in'} 349 | include_graphics("images/horrormovie.png") 350 | ``` 351 | 352 | \centering https://youtu.be/s3JldKoA0zw 353 | 354 | ::: 355 | 356 | ## ¿De dónde sale este número? 357 | 358 | ```{r out.width = '4.5in', out.height = '1.5in'} 359 | include_graphics("images/Word-sentence.png") 360 | ``` 361 | 362 | 363 | 364 | ## Documentos dinámicos con Rmarkdown 365 | 366 | ```{r} 367 | surv.diff <- 30 368 | ``` 369 | 370 | *Rmarkdown*: 371 | 372 | \ \hspace{5mm} Survival in population A was `` `r inline_expr("surv.diff")` `` % higher 373 | 374 | \vspace{6mm} 375 | 376 | *Output*: 377 | 378 | \ \hspace{5mm} Survival in population A was **`r surv.diff`** % higher 379 | 380 | 381 | 382 | 383 | ## Documentos dinámicos con Rmarkdown 384 | 385 | ```{r} 386 | x = runif(86) 387 | y = rnorm(86, 0.3 + 1.1*x, 0.1) 388 | datos <- data.frame(x, y) 389 | ``` 390 | 391 | 392 | ```{r echo=TRUE, eval=FALSE} 393 | datos <- read.csv("datos.csv") 394 | ``` 395 | 396 | *Rmarkdown:* 397 | 398 | \ \hspace{5mm} We measured `` `r inline_expr("nrow(datos)")` `` individuals 399 | 400 | \vspace{5mm} 401 | 402 | *Output:* 403 | 404 | \ \hspace{5mm} We measured **`r nrow(datos)`** individuals 405 | 406 | \vspace{1cm} 407 | 408 | \centering ¡Mucho mejor que copiar y pegar! 409 | 410 | 411 | 412 | 413 | ## Rmarkdown: texto + código 414 | 415 | ```{r out.width = '4.5in', out.height = '2.4in'} 416 | include_graphics("images/Rmd-exp.png") 417 | ``` 418 | 419 | ## Regenera Word/PDF/html... con un click 420 | 421 | ```{r out.width = '4.3in', out.height = '2.8in'} 422 | include_graphics("images/Fig3.png") 423 | ``` 424 | 425 | 426 | ## Rmarkdown: resultados trazables y ejecutables 427 | 428 | ```{r out.width = '4.5in', out.height = '1.7in'} 429 | include_graphics("images/Fig1.jpg") 430 | ``` 431 | 432 | \raggedright 433 | \tiny [Rodríguez-Sánchez et al. 2016](https://www.revistaecosistemas.net/index.php/ecosistemas/article/view/1178) 434 | \raggedleft 435 | 436 | 437 | 438 | ## Rmarkdown: generación automática de tablas 439 | 440 | ```{r} 441 | library(xtable) 442 | #model <- lm(y ~ x, data = datos) 443 | datos <- read.table("data.txt", header = TRUE) 444 | model <- lm(happiness ~ sunshine, data = datos) 445 | ``` 446 | 447 | ```{r echo=TRUE, eval=FALSE} 448 | model <- lm(happiness ~ sunshine, data = datos) 449 | xtable(model) 450 | ``` 451 | 452 | ```{r results = "asis"} 453 | print(xtable(model), comment = FALSE) 454 | ``` 455 | 456 | 457 | ::: hide ::: 458 | 459 | ## `equatiomatic` describe la estructura de los modelos 460 | 461 | We fitted a linear model: 462 | 463 | ```{r echo=T, results="asis"} 464 | model <- lm(happiness ~ sunshine, data = datos) 465 | equatiomatic::extract_eq(model) 466 | ``` 467 | 468 | ::: 469 | 470 | 471 | 472 | ## ¡Modelos que se auto-describen! 473 | 474 | \scriptsize 475 | 476 | ```{r echo=T, results="asis"} 477 | library("report") 478 | model <- lm(happiness ~ sunshine, data = datos) 479 | report(model) 480 | ``` 481 | 482 | \normalsize 483 | 484 | ## Revisa tu gramática 485 | 486 | \footnotesize https://github.com/ropenscilabs/gramr 487 | 488 | ```{r out.width = '6in', out.height = '2in'} 489 | include_graphics("images/gramr.jpg") 490 | ``` 491 | 492 | 493 | ::: hide ::: 494 | ----- 495 | 496 | \large 497 | 498 | ¿Cómo incluir la bibliografía 499 | 500 | en Rmarkdown? 501 | 502 | \normalsize 503 | 504 | 505 | ## `rcrossref`: cita artículos vía DOI 506 | 507 | ```{r out.width = '3.8in', out.height = '3in'} 508 | include_graphics("images/rcrossref-doi.png") 509 | ``` 510 | 511 | 512 | ## `rcrossref`: búsqueda de artículos 513 | 514 | ```{r out.width = '3.7in', out.height = '3in'} 515 | include_graphics("images/rcrossref-metadata.png") 516 | ``` 517 | 518 | ## `citr`: citar artículo de base de datos (Zotero) 519 | 520 | ```{r out.width = '3.2in', out.height = '2.8in'} 521 | include_graphics("images/citr.png") 522 | ``` 523 | 524 | ::: 525 | 526 | 527 | ## Bibliografía: Cita via DOI, búsqueda, Zotero... (RStudio 1.4) 528 | 529 | ```{r out.width = '3.5in', out.height = '2.5in'} 530 | include_graphics("images/citations-Rstudio14.png") 531 | ``` 532 | 533 | \tiny https://rstudio.github.io/visual-markdown-editing/#/citations 534 | 535 | 536 | ## ¡No olvides citar los paquetes de R! 537 | 538 | Rmarkdown: 539 | 540 | \ \hspace{5mm} `knitr::write_bib()` 541 | 542 | \vspace{1cm} 543 | 544 | Procesador texto: 545 | 546 | \ \hspace{5mm} `grateful::cite_packages()` 547 | 548 | 549 | ## Formatea bibliografía para cualquier revista 550 | 551 | ```{r out.width = '3in', out.height = '1.2in'} 552 | include_graphics("images/csl.png") 553 | ``` 554 | 555 | Repositorio de 'citation styles' (CSL): 556 | 557 | \scriptsize https://www.zotero.org/styles 558 | \scriptsize https://github.com/citation-style-language/styles 559 | 560 | 561 | ## Plantillas Rmarkdown 562 | 563 | \begin{columns}[c] 564 | 565 | \column{0.3\textwidth} 566 | 567 | - rticles 568 | 569 | - papaja 570 | 571 | - rrtools 572 | 573 | - pinp 574 | 575 | - rmdTemplates 576 | 577 | - GitHub! 578 | 579 | 580 | \column{0.7\textwidth} 581 | 582 | ```{r out.width = '2.3in', out.height = '2.8in'} 583 | include_graphics("images/pnas.png") 584 | ``` 585 | 586 | \end{columns} 587 | 588 | 589 | ::: hide ::: 590 | ## ¡No solo R! Python, Julia, C++, SQL, Stan, etc 591 | 592 | `knitr` engines: 593 | 594 | ```{r warning=FALSE} 595 | kable(matrix(sort(names(knitr::knit_engines$get())), nrow = 6, ncol =7)) 596 | ``` 597 | ::: 598 | 599 | ## Documentos dinámicos con Rmarkdown 600 | 601 | https://rmarkdown.rstudio.com/ 602 | 603 | ```{r out.width = '2in', out.height = '2in'} 604 | include_graphics("images/rmdlogo.png") 605 | ``` 606 | 607 | 608 | 609 | 610 | ## 'Visual Rmarkdown'en Rstudio 1.4 trae múltiples ventajas 611 | 612 | \footnotesize 613 | **¡Como escribir en procesador de texto, pero todas las ventajas de Rmarkdown!** 614 | \normalsize 615 | 616 | ```{r out.width = '3.2in', out.height = '2.5in'} 617 | include_graphics("images/visualRmd.png") 618 | ``` 619 | 620 | \tiny https://rstudio.github.io/visual-markdown-editing 621 | 622 | 623 | # Control de flujos de trabajo 624 | 625 | --- 626 | 627 | En proyectos complejos es necesario **organizar las piezas** 628 | 629 | ```{r} 630 | include_graphics("images/puzzle.jpeg") 631 | ``` 632 | 633 | 634 | 635 | ## Script maestro ejecuta código en orden adecuado 636 | 637 | `makefile.R` 638 | 639 | ```{r echo=TRUE, eval=FALSE} 640 | source("clean_data.R") 641 | 642 | source("fit_model.R") 643 | 644 | source("generate_report.R") 645 | ``` 646 | 647 | 648 | ## Script maestro ejecuta código en orden adecuado 649 | 650 | \tiny https://github.com/Pakillo/exclosures-Almoraima 651 | 652 | \scriptsize 653 | 654 | ```{r echo=TRUE, eval=FALSE} 655 | #### READ AND PREPROCESS DATA ##### 656 | 657 | ## Read site info 658 | read_siteinfo("data-raw/sites_info_raw.csv") 659 | 660 | ## Read and prepare species info 661 | read_sppinfo(sppdata = "data-raw/species_info_raw.csv") 662 | 663 | ## Prepare dataset 664 | make_dataset() 665 | 666 | 667 | #### EXPLORATORY ANALYSIS #### 668 | rmarkdown::render("analyses/EDA.Rmd") 669 | 670 | 671 | #### MANUSCRIPT #### 672 | rmarkdown::render("manuscript/cercados_Almoraima/cercados_Almoraima.Rmd") 673 | ``` 674 | 675 | \normalsize 676 | 677 | 678 | 679 | ## `drake`/`targets`: control total del flujo de trabajo 680 | 681 | ```{r out.width = '4in', out.height = '1.9in'} 682 | include_graphics("images/drake-plan.png") 683 | ``` 684 | 685 | \footnotesize https://docs.ropensci.org/drake/ 686 | 687 | \footnotesize https://wlandau.github.io/targets/ 688 | 689 | 690 | # Control de dependencias 691 | 692 | ::: hide ::: 693 | --- 694 | 695 | ```{r out.width = '2.3in', out.height = '2.5in'} 696 | include_graphics("images/sotobosque.png") 697 | ``` 698 | ::: 699 | 700 | --- 701 | 702 | Cambios en paquetes pueden romper/alterar el análisis 703 | 704 | ¿Cómo reproducir el análisis dentro de un año, o en otro ordenador? 705 | 706 | 707 | ## `sessionInfo` registra paquetes usados y versiones, OS... 708 | 709 | \tiny 710 | 711 | ```{r echo=TRUE} 712 | sessionInfo() 713 | ``` 714 | 715 | \normalsize 716 | 717 | 718 | ## `checkpoint` reconstruye paquetes en fecha determinada 719 | 720 | ```{r eval=FALSE, echo=TRUE} 721 | library("checkpoint") 722 | checkpoint("2019-10-08") 723 | 724 | source("analysis.R") 725 | ``` 726 | 727 | 1. Detecta paquetes usados en el proyecto 728 | 729 | 2. Instala versión correspondiente a esa fecha (solo CRAN) 730 | 731 | 3. Instalación independiente (no interfiere con paquetes ya instalados) 732 | 733 | 734 | ## `automagic` registra e instala paquetes (CRAN + GitHub) 735 | 736 | \scriptsize 737 | 738 | ```{r eval=FALSE, echo=TRUE} 739 | automagic::make_deps_file() 740 | ``` 741 | Crea `deps.yaml` especificando dependencias: 742 | \tiny 743 | ```yaml 744 | - Package: equatiomatic 745 | Repository: CRAN 746 | Version: 0.1.0 747 | 748 | - Package: report 749 | GithubUsername: easystats 750 | GithubRepo: report 751 | GithubRef: HEAD 752 | GithubSHA1: c48a4bb0a40df7116bc502aa3ce2cbbc9d70b7e2 753 | ``` 754 | \scriptsize 755 | Para instalar todas esas dependencias: 756 | ```{r eval=FALSE, echo=TRUE} 757 | automagic() 758 | ``` 759 | 760 | \normalsize 761 | 762 | ## `renv` también controla las dependencias del proyecto 763 | 764 | ```{r echo=TRUE, eval=FALSE} 765 | renv::init() 766 | 767 | renv::snapshot() 768 | # Captura dependencias en fichero lockfile 769 | 770 | renv::restore() 771 | # Regenera dependencias a partir del lockfile 772 | ``` 773 | 774 | https://environments.rstudio.com/ 775 | 776 | --- 777 | 778 | Para asegurar la reproducibilidad, 779 | 780 | además de los paquetes de R 781 | 782 | necesitamos controlar 783 | 784 | el **sistema/entorno computacional** 785 | 786 | 787 | --- 788 | 789 | \large 790 | 791 | `Docker` permite recrear sistemas virtuales 792 | 793 | a partir de un `Dockerfile` 794 | 795 | que especifica la configuración 796 | 797 | \normalsize 798 | 799 | ## `liftr`: procesa documento Rmd en un contenedor Docker 800 | 801 | ```{r out.width = '4.3in', out.height = '1.3in'} 802 | include_graphics("images/liftr.png") 803 | ``` 804 | 805 | \footnotesize https://liftr.me/ 806 | 807 | ## `containerit` facilita creación de Dockerfile 808 | 809 | ```{r echo=TRUE, eval=FALSE} 810 | library("containerit") 811 | 812 | dockfile <- dockerfile(from = "mypaper.Rmd") 813 | ``` 814 | 815 | \footnotesize https://o2r.info/containerit 816 | 817 | 818 | ## `holepunch`: reproduce análisis en la nube (Binder) 819 | 820 | ```{r out.width = '4in', out.height = '2.5in'} 821 | include_graphics("images/holepunch.png") 822 | ``` 823 | 824 | \footnotesize https://karthik.github.io/holepunch/ 825 | 826 | 827 | 828 | # Organización del proyecto 829 | 830 | ## Principios sobre organización de proyectos 831 | 832 | - README 833 | 834 | - Licencia 835 | 836 | - Datos brutos + limpios + código depuración 837 | 838 | - Código modular (funciones) 839 | 840 | - Makefile 841 | 842 | - Control de dependencias 843 | 844 | \tiny 845 | [Noble 2009](https://doi.org/10.1371/journal.pcbi.1000424), [Rodriguez-Sanchez et al 2016](https://www.revistaecosistemas.net/index.php/ecosistemas/article/view/1178), [Wilson et al 2017]( https://doi.org/10.1371/journal.pcbi.1005510) 846 | \normalsize 847 | 848 | 849 | ::: hide ::: 850 | 851 | --- 852 | 853 | \large 854 | 855 | **Research compendium:** 856 | 857 | - Datos + Código + Texto 858 | 859 | - Estructura de paquete de R 860 | 861 | \normalsize 862 | 863 | 864 | 865 | ## Proyectos estructurados como paquetes de R 866 | 867 | >- Estructura estándar, consistente 868 | 869 | >- Promueve código modular, bien documentado y testado 870 | 871 | >- Fácil de compartir y ejecutar 872 | 873 | >- Integración continua (Travis, GitHub Actions, etc) 874 | 875 | >- Revisión automática del código con `goodpractice` 876 | 877 | >- Muy fácil crear website del proyecto con `pkgdown` 878 | 879 | \raggedright 880 | \tiny 881 | [Rodríguez-Sánchez et al. 2016](https://www.revistaecosistemas.net/index.php/ecosistemas/article/view/1178), [Marwick et al 2018](https://doi.org/10.1080/00031305.2017.1375986), but see [McBain 2020](https://milesmcbain.xyz/posts/an-okay-idea/) 882 | \raggedleft 883 | ::: 884 | 885 | 886 | 887 | ## rrtools facilita la creación de compendios (paquetes) 888 | 889 | \footnotesize 890 | 891 | ```{r echo=TRUE, eval=FALSE} 892 | library("rrtools") 893 | 894 | use_compendium("~/mynewproject/") # crea proyecto 895 | 896 | use_readme_rmd() # crea README 897 | 898 | use_analysis() # crea carpeta con manuscrito Rmd 899 | 900 | use_dockerfile() # crea Dockerfile 901 | 902 | use_travis() # Usa Travis para integración continua 903 | 904 | use_testthat() # Usa tests para las funciones 905 | ``` 906 | 907 | \normalsize 908 | 909 | 910 | ## `rrtools.addin` te guía para crear un nuevo proyecto 911 | 912 | ```{r out.width = '4in', out.height = '1.9in'} 913 | include_graphics("images/rrtools-addin.png") 914 | ``` 915 | 916 | \footnotesize https://github.com/nevrome/rrtools.addin 917 | 918 | 919 | ::: hide ::: 920 | ## Estructura del proyecto 921 | 922 | \scriptsize 923 | ``` 924 | - README 925 | - LICENSE 926 | - DESCRIPTION 927 | - travis.yml 928 | - Dockerfile 929 | - analysis/ 930 | | 931 | |- paper/ 932 | |- paper.Rmd 933 | |- references.bib 934 | | 935 | |- figures/ 936 | | 937 | |- data/ 938 | |- raw_data/ 939 | |- derived_data/ 940 | ``` 941 | ::: 942 | 943 | 944 | ## Estructura del proyecto (con funciones) 945 | 946 | \scriptsize 947 | ``` 948 | - README 949 | - LICENSE 950 | - DESCRIPTION 951 | - travis.yml 952 | - Dockerfile 953 | - analysis/ 954 | | 955 | |- paper/ 956 | |- paper.Rmd 957 | |- references.bib 958 | | 959 | |- figures/ 960 | | 961 | |- data/ 962 | |- raw_data/ 963 | |- derived_data/ 964 | - R/ 965 | |-functions.R 966 | - man/ 967 | ``` 968 | 969 | \normalsize 970 | 971 | 972 | 973 | ## Integración continua: chequeo continuo tras cada 'commit' 974 | 975 | \footnotesize Travis-CI, Circle-CI, GitHub Actions... 976 | 977 | ```{r out.width = '3.5in', out.height = '2.7in'} 978 | include_graphics("images/travis.PNG") 979 | ``` 980 | 981 | 982 | 983 | ## `workflowr`: proyectos reproducibles con website 984 | 985 | \footnotesize 986 | ```{r echo=TRUE, eval=FALSE} 987 | library("workflowr") 988 | wflow_start("~/newproject") 989 | ``` 990 | \normalsize 991 | 992 | ```{r out.width = '3.5in', out.height = '2.5in'} 993 | include_graphics("images/workflowr.png") 994 | ``` 995 | 996 | 997 | # Recapitulación 998 | 999 | 1000 | ## Recapitulación 1001 | 1002 | >- **Archivar** DATOS + CÓDIGO 1003 | 1004 | >- **Rmarkdown**: integra análisis + texto en documento dinámico 1005 | 1006 | >- **Control de operaciones**: makefile, drake/targets 1007 | 1008 | >- **Dependencias**: sessionInfo -> paquetes R -> Docker 1009 | 1010 | >- **Estructura consistente de proyectos**: rrtools, workflowr... 1011 | 1012 | 1013 | --- 1014 | 1015 | ```{r out.width = '4.5in', out.height = '1.7in'} 1016 | include_graphics("images/Fig1.jpg") 1017 | ``` 1018 | 1019 | 1020 | 1021 | 1022 | -------------------------------------------------------------------------------- /slides.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/writing-reproducible-manuscripts/bbc744b70814d76be67c4aa520e45bc9e3fd3ccb/slides.pdf -------------------------------------------------------------------------------- /writing-reproducible-manuscripts.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | --------------------------------------------------------------------------------