According to R Studio
“R Markdown is a format that enables easy authoring of reproducible web reports from R. It combines the core syntax of Markdown (an easy-to-write plain text format for web content) with embedded R code chunks that are run so their output can be included in the final document”.
From Penn State Statistics
Introduction to creating dynamic R statistical reports in PDF or HTML:
What do you mean by dynamic?
The traditional way to write a report is:
- Run your analysis in software, like SPSS or R and manually save our output
- i.e. saving the ANOVA table or using pdf() to save the graphs
- Type your your description and interpretation in a text editor like Word
- either drag/drop tables and figures, or worse copy-paste and retype all the numbers
A report written in this way can be problematic. For instance, imagine your Mentor/collaborator/journal reviewer telling you that they want to use a sub-sample instead of the entire sample. Or to include a nother variable. You would have to redo all of your work!!
Therefore, in this way dynamic also means reproducible, in the sense that people who get the file from you can reproduce the entire work in the report.
How does R Markdown work out to be a .pdf or .html file?
R Markdown
is a file with the file extension .Rmd, the knitr
package will then transform the file into a Markdown file with the extension .md. Then Rstudio can:
Use
LaTeX
to transform the file into a .pdfLoad another package called
markdown
to transform the file into .htmlUse Pandoc to even convert to file to a Word document (ugly)
Is this a popular method for creating reports?
Check out Rpubs. This website shares lots of documents written in the way we will introduce below.
Background Information
R Markdown
documents are fully reproducible. Use a productive notebook interface to weave together narrative text and code to produce elegantly formatted output. Use multiple languages including R, Python, and SQL.
knitr
is an engine for dynamic report generation with R. It is a package in the statistical programming language R that enables integration of R code into LaTeX, LyX, HTML, Markdown, AsciiDoc, and text documents.
Three Downloads to Install
1. R
from www.r-project.org
Get the latest released version of FREE Base R from CRAN
- Choose a mirror close to your location
- Select base R for your computer (Windows, Mac, ect.)
- The defaults are good…don’t change them…just keep clicking ‘Next’
2 R Studio
from www.rstudio.com
Get the latest version of the FREE Open Source Desktop Edition of R Studio
- The defaults are good…don’t change them…just keep clicking ‘Next’
3. LaTeX
depends on your operating system
Mac:
MacTeX
from http://tug.org/mactex/
- Download (5+ min) to a folder and them double click on the PKG file
- Follow the installation instructions.
- You don’t need to open anything after MacTeX is finished installing.
Windows:
MikTeX
http://miktex.org/download
- Pick the latest version of the Net Installer, not the Basic!
- You need the full version 64-bit is better, if you have a 64-bit machine
- When your download is complete, run the downloaded installer.
- Windows may ask you if you want to “allow this app from an unknown publisher to make changes to your PC”. If it does, make sure to click Yes!
- This is the slowest part…