2020-02-27 12:28:53

Preliminaries

Announcements

Today’s topics

  • Websites with R Markdown
  • Slides with R Markdown
  • (Optional) Doing useful things en masse

Websites with R Markdown

Why?

  • Easy-peasy
  • Edit in R Markdown, render to HTML
  • Rapid (re)deployment

Anatomy of R Markdown-generated site

  • _site.yml
  • index.Rmd
  • other_pages.Rmd

How to…

  • Build the site
  • Render
  • View
  • Edit
  • Rebuild, re-render, view, edit, etc.

  • Commit and push
  • Pull from dev branch (if you’re using one)
  • Enable GitHub pages on repo (if not already done)

  • Bask in the glow…

Your turn

  • Local or GitHub?
  • If local, make new local folder
  • Create site
  • Render
  • View index.html

Slides with R Markdown

Virtues…

  • Easy to make, edit, version-control, share
  • Slides as webpages \(\rightarrow\) present from a browser
  • Share in public GitHub repo \(\rightarrow\) present from any computer anywhere

  • Incorporate R code (rerender figures, etc.)
  • Incorporate live links to external resources (video, web pages, etc.)
  • Possibility of reusing other R Markdown docs

Vices…

  • Not always the prettiest (unless you customize)
  • Sometimes hard to export as PDF
  • Web resources disappear, end up behind paywalls

Anatomy of a slide file

  • YAML header
  • Slides
    • With title text
    • Without title text/header

Many *_presentation slide options

  • ioslides_presentation (HTML)
  • slidy_presentation (HTML)
  • beamer_presentation (PDF)
    • requires LaTex or (install.packages("tinytex"))
  • powerpoint_presentation (PPTX)
    • requires MS Powerpoint

  • revealjs::revealjs_presentation (HTML)
    • install.packages("revealjs")
  • xaringen (HTML)
    • install.packages("xaringen")

Examples

Read the docs!

Other bits

  • Add custom HTML
  • Tweak the CSS

Your turn

  • File/New File/R Markdown…/Presentation/
  • Examine the YAML header
  • Try a customization

Doing useful things en masse

Parameters in R Markdown files

Embed ‘child’ documents

  • If you repeat the same thing 2-3x…consider automating

Automating by-participant plots

Next time

  • Student’s choice

Resources

Software

This talk was produced on 2020-02-27 in RStudio using R Markdown. The code and materials used to generate the slides may be found at https://github.com/psu-psychology/psy-525-reproducible-research-2020. Information about the R Session that produced the code is as follows:

## R version 3.6.2 (2019-12-12)
## Platform: x86_64-apple-darwin15.6.0 (64-bit)
## Running under: macOS Mojave 10.14.6
## 
## Matrix products: default
## BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/3.6/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 
## [6] methods   base     
## 
## other attached packages:
## [1] lme4_1.1-21     Matrix_1.2-18   gapminder_0.3.0
## [4] dplyr_0.8.4     ggplot2_3.2.1  
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_1.0.3         nloptr_1.2.1      
##  [3] plyr_1.8.5         pillar_1.4.3      
##  [5] compiler_3.6.2     tools_3.6.2       
##  [7] boot_1.3-23        digest_0.6.25     
##  [9] packrat_0.5.0      nlme_3.1-142      
## [11] lattice_0.20-38    evaluate_0.14     
## [13] lifecycle_0.1.0    tibble_2.1.3      
## [15] gtable_0.3.0       pkgconfig_2.0.3   
## [17] rlang_0.4.4        yaml_2.2.1        
## [19] xfun_0.12          withr_2.1.2       
## [21] stringr_1.4.0      knitr_1.28        
## [23] grid_3.6.2         tidyselect_1.0.0  
## [25] tufte_0.5          glue_1.3.1        
## [27] R6_2.4.1           databraryapi_0.1.9
## [29] rmarkdown_2.1      minqa_1.2.4       
## [31] purrr_0.3.3        farver_2.0.3      
## [33] reshape2_1.4.3     magrittr_1.5      
## [35] MASS_7.3-51.5      splines_3.6.2     
## [37] scales_1.1.0       htmltools_0.4.0   
## [39] assertthat_0.2.1   colorspace_1.4-1  
## [41] labeling_0.3       stringi_1.4.6     
## [43] lazyeval_0.2.2     munsell_0.5.0     
## [45] crayon_1.3.4

References