Reproducibility

What’s reproducibility?

A different analyst re-performs the analysis with the same code and the same data and obtains the same result.

Reproducibility vs Repeatability vs Replicability

session info

Reproducibility

RMarkdown

Clicking the knit button, will knit your document to create different types of reports. The default is html.

How to knit an Rmd

Code Chunks

Options for code chunks

After knitting:
1) echo - determines if your code should be shown or not
- TRUE = code is shown (default)
- FALSE = code is not shown (but might be run…depends on eval)
2) eval - determines if your code should be evaluated (run) or not
- TRUE = code is run (default)
- FALSE = code is not run (but might be shown…depends on echo)
3) message = FALSE -suppresses messages when your run your code

RMarkdown syntax

Before: Markdown sytax before rendering

After knit: Result of markdown sytax after rendering

RMarkdown syntax

Go to File > Help > Cheatsheets > R Markdown Cheatsheet

Final Project

Specific guidelines and example on website

Turn in through CoursePlus:
1) RMarkdown file
2) html file

Session Info

session info

Session info helps

sessionInfo()
R version 4.0.5 (2021-03-31)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] forcats_0.5.1   stringr_1.4.0   purrr_0.3.4     tidyr_1.1.3    
 [5] tibble_3.1.3    ggplot2_3.3.5   tidyverse_1.3.1 dplyr_1.0.7    
 [9] readr_1.4.0     knitr_1.33     

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.1 xfun_0.25        bslib_0.3.1      haven_2.4.3     
 [5] colorspace_2.0-2 vctrs_0.3.8      generics_0.1.0   htmltools_0.5.2 
 [9] yaml_2.2.1       utf8_1.2.2       rlang_0.4.11     jquerylib_0.1.4 
[13] pillar_1.6.2     withr_2.4.2      glue_1.4.2       DBI_1.1.1       
[17] dbplyr_2.1.1     modelr_0.1.8     readxl_1.3.1     lifecycle_1.0.0 
[21] munsell_0.5.0    gtable_0.3.0     cellranger_1.1.0 rvest_1.0.1     
[25] evaluate_0.14    fastmap_1.1.0    fansi_0.5.0      highr_0.9       
[29] broom_0.7.10     Rcpp_1.0.7       backports_1.2.1  scales_1.1.1    
[33] jsonlite_1.7.2   fs_1.5.0         hms_1.1.0        digest_0.6.27   
[37] stringi_1.7.3    grid_4.0.5       cli_3.0.1        tools_4.0.5     
[41] magrittr_2.0.1   sass_0.4.0       crayon_1.4.1     pkgconfig_2.0.3 
[45] ellipsis_0.3.2   xml2_1.3.2       reprex_2.0.1     lubridate_1.7.10
[49] rstudioapi_0.13  assertthat_0.2.1 rmarkdown_2.10   httr_1.4.2      
[53] R6_2.5.1         compiler_4.0.5  

DRY code

DRY is an acronym: “Don’t repeat yourself” [@Smith2013].

“I hate code, and I want as little of it as possible in our product.” - Jack Diedrich

More resources

These are just some quick tips, for more information: