2020-02-27 12:28:14
File/New File/R Markdown...
Document
, call it something sensible like psy-525-rmarkdown-testbed
testbed.Rmd
*italics*
or _italics_
**boldface**
or __boldface__
~~strikethrough~~
[Clickable URLs](http://www.psu.edu)
# This is a Heading 1 ## This is a Heading 2 ### This is a Heading 3
Code:
- An item - A nested item - A doubly-nested item - Another item
Code:
1. An enumerated item - A nested item 1. A second enumerated item
Notice how the numbers are incremented automatically!
<CTRL>+2
goes to console<CTRL>+1
goes to source<UP-ARROW>
<RETURN>
<COMMAND><ALT>+I
(Mac OS); <CTRL><ALT>+I
(Windows) inserts a chunkCode:
> Four score and seven years ago, some famous President > spoke infamous words that would live on throughout history. > These words are famous enough that I want to highlight them with a block quote.
Four score and seven years ago, some famous President spoke infamous words that would live on throughout history. These words are famous enough that I want to highlight them with a block quote.
![Alt text](/path/to/img.jpg)
<!- This is a comment ->
.Rmd
extensionCode (in a chunk):
```{r} x = rnorm(n = 100, mean = 0, sd = 1) # N(0,1) y = rnorm(n = 100, mean = 2, sd = 0.5) # N(2, 0.5) ```
Code (in a chunk):
```{r} summary(x) summary(y) ```
## Min. 1st Qu. Median Mean 3rd Qu. Max. ## -2.1435 -0.6226 0.1075 0.1305 0.8273 2.5863
## Min. 1st Qu. Median Mean 3rd Qu. Max. ## 0.7052 1.6464 1.9712 1.9492 2.2385 2.8509
Code (in a chunk):
```{r} hist(x) ```
Code (in a chunk):
```{r} hist(y) ```
Code (in a chunk):
```{r} plot(x,y) ```
Code (in a chunk):
```{r rog, fig.cap="Rick's pic from Databrary"} knitr::include_graphics("https://nyu.databrary.org/party/6/avatar") ```
Code (outside a chunk):
<img src="img/sleic.jpg" height=500px>
Height parameter (or, e.g. height=500px
) is optional, but useful. Remember Markdown -> HTML.
HTML Code (outside a chunk–not talking to R)
<iframe width="420" height="315" src="https://www.youtube.com/embed/9hUy9ePyo6Q" frameborder="0" allowfullscreen> </iframe>
Code (in a chunk):
```{r} summ.x = summary(x) summ.y = summary(y) names(summ.x) # Figure out variable names for indexing ```
## [1] "Min." "1st Qu." "Median" "Mean" "3rd Qu." ## [6] "Max."
sprintf()
sprintf("%2.3f", 14.7666)
gives 14.77help("sprintf")
Index by variable name: X lies within the range of [-2.1434695, 2.5862562].
Index by numeric index: The (y-x) difference in means is 1.8187584.
Calculate and report: The correlation between x and y is -0.2262571.
Markdown (not in a chunk–not talking to R) using LaTex syntax.
$$e=mc^{2}$$
\[e=mc^{2}\]
--- title: "psy-525-rmarkdown-testbed" author: "Rick Gilmore" date: "2020-02-27 12:28:14" output: html_document: self_contained: true word_document: fig_width: 5 fig_height: 5 fig_caption: false df_print: kable pdf_document: default ioslides_presentation: default powerpoint_presentation: default ---
echo=TRUE
prints your R codeecho=FALSE
runs but does not print your code; include=FALSE
does also.eval=FALSE
prevents a chunk from executingknit
button converts your document to the default formatoutput:
parameterknit
button gives other optionsknitr
is an R package that R Markdown depends upon heavilyIn the console (not your R Markdown document):
> rmarkdown::render("testbed.Rmd")
In the console:
> rmarkdown::render("testbed.Rmd", output_format = c("html_document", "word_document", "pdf_document"))
Makes copies in three different formats: testbed.html
, testbed.docx
, and testbed.pdf
.
rmarkdown::render()
commandoutput_file = myslides.ioslides.html
or output_file = myslides.slidy.html
to specify different output file targets.output_dir = reports
or output_dir = docx
to direct output to a specific directory.params:
In your header:
--- title: "psy-525-rmarkdown-testbed" author: "Rick Gilmore" date: "2020-02-27 12:28:14" output: html_document: default params: name: Joe quest: "to find the Holy Grail" ---
In the console (for example):
> rmarkdown::render("testbed.Rmd", params=list(name="Francine"))
Make a self-contained HTML file that includes any plots you’ve made or graphics you’ve embedded. Great for sharing locally (i.e, as a document not over the web).
--- output: html_document: self_contained: true ---
Add a table of contents. toc_depth
controls how “deep” into your header hierarchy the table of contents should go.
--- output: html_document: toc: true toc_depth: 2 ---
Add toc_float: true
to make the table of contents “float” to the side of your document.
--- output: html_document: toc: true toc_depth: 2 toc_float: true ---
Add number_sections: true
to make the table of contents automatically generate a hierarchical set of numbers–1.0, 1.2, 2.1, etc.–based on your header hierarchy. Remember, #
is header 1, ##
is header 2, etc.
--- output: html_document: toc: true toc_depth: 2 toc_float: true number_sections: true ---
Include your code chunks (include = TRUE
) but hide them until someone wants to see them by adding code_folding: hide
to your YAML header.
--- output: html_document: toc: true toc_depth: 2 toc_float: true number_sections: true code_folding: hide ---
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] DiagrammeR_1.0.5 forcats_0.4.0 stringr_1.4.0 ## [4] dplyr_0.8.3 purrr_0.3.3 readr_1.3.1 ## [7] tidyr_1.0.0 tibble_2.1.3 ggplot2_3.2.1 ## [10] tidyverse_1.3.0 seriation_1.2-8 ## ## loaded via a namespace (and not attached): ## [1] viridis_0.5.1 httr_1.4.1 ## [3] tufte_0.5 jsonlite_1.6 ## [5] viridisLite_0.3.0 foreach_1.4.8 ## [7] modelr_0.1.5 gtools_3.8.1 ## [9] assertthat_0.2.1 highr_0.8 ## [11] cellranger_1.1.0 yaml_2.2.0 ## [13] pillar_1.4.3 backports_1.1.5 ## [15] lattice_0.20-38 glue_1.3.1 ## [17] digest_0.6.23 RColorBrewer_1.1-2 ## [19] rvest_0.3.5 colorspace_1.4-1 ## [21] htmltools_0.4.0 pkgconfig_2.0.3 ## [23] broom_0.5.3 haven_2.2.0 ## [25] scales_1.1.0 gdata_2.18.0 ## [27] farver_2.0.3 generics_0.0.2 ## [29] withr_2.1.2 lazyeval_0.2.2 ## [31] cli_2.0.1 magrittr_1.5 ## [33] crayon_1.3.4 readxl_1.3.1 ## [35] evaluate_0.14 fs_1.3.1 ## [37] fansi_0.4.1 nlme_3.1-142 ## [39] MASS_7.3-51.5 gplots_3.0.1.2 ## [41] xml2_1.2.2 tools_3.6.2 ## [43] registry_0.5-1 hms_0.5.3 ## [45] lifecycle_0.1.0 munsell_0.5.0 ## [47] reprex_0.3.0 cluster_2.1.0 ## [49] packrat_0.5.0 compiler_3.6.2 ## [51] caTools_1.18.0 rlang_0.4.4 ## [53] grid_3.6.2 iterators_1.0.12 ## [55] rstudioapi_0.10 visNetwork_2.0.9 ## [57] htmlwidgets_1.5.1 labeling_0.3 ## [59] bitops_1.0-6 rmarkdown_2.1 ## [61] gtable_0.3.0 codetools_0.2-16 ## [63] DBI_1.1.0 TSP_1.1-8 ## [65] R6_2.4.1 gridExtra_2.3 ## [67] lubridate_1.7.4 knitr_1.27 ## [69] pwr_1.2-2 utf8_1.1.4 ## [71] KernSmooth_2.23-16 dendextend_1.13.3 ## [73] stringi_1.4.5 Rcpp_1.0.3 ## [75] vctrs_0.2.2 gclus_1.3.2 ## [77] dbplyr_1.4.2 tidyselect_1.0.0 ## [79] xfun_0.12