r markdown - shippensburg university of...
TRANSCRIPT
R Markdown!The Basics!
ThiswastheoriginalworkflowinRStudiousing
Rscriptfiles(*.R)
RNotebooksbringtogetherprose,code,andresults.Theyaregreatfor• CommunicaCngresults
tothosewhodonotneedtoseethecode
• CollaboraCngwithotherdatascienCstsinterestedintheresultsandthecode
• Actuallydoingdatascience
R Markdown
Components of an R Notebook
TextusingMarkdown(andLaTeX)
CodeusingR(orotherlanguages)
YAMLheader
Text Using Markdown
Headers
# Header 1
## Header 2
### Header 3
#### Header 4
##### Header 5
###### Header 6
Header 1 Header 1 Header 1 Header 1 Header 1 Header 1
Use#’stocreateheadersfor
chapters,secCons,subsecCons,etc.
Text
italics
bold
code
Text
Text
_italics_
_ _bold_ _
`code`
Textisrenderedasplaintext.Useunderscores(_)tomakeitalics,twounderscores(__)tomakebold,backCckstomakecode.
Addtwospacesattheendofalinetostartanewline
Lists
Bullet points* item 1* item 2
Numbered lists1. item 12. item 2
Bullet points• item 1• item 2
Numbered lists1. item 12. item 2
Useasteriskstomakebulletpoints.Usenumberstomakenumberedlists.
Hyperlinks
This is a [link](www.ship.edu).
This is a link.
Usebracketstodenotealink.PlacetheURLinparentheses.
EquationsAccording to Einstein, $E=mc^2$.
According to Einstein, E = mc2.
WriteequaConswithLaTeXcommandsandsurroundthemin$’s.
Equation Blocks
According to Einstein, $$E=mc^2$$.
According to Einstein,
E = mc2.Usetwo$’stomakecenteredequaConblocks.
TheRStudiologo.
Images
![](logo.png) The RStudio logo.
Usealinkprecededbyan!toinsertanimage.LinkshouldbeaURLorfilepath.
Code Chunks
Code Chunks
InfinalkniTeddocument(html,pdf,etc.)InRnotebook
Chunk Options
Forcode:evaldeterminesifthecodeisevaluated
Chunk Options
Forresults:echodeterminesiftheoutputisshown,messageandwarningdetermine
iftheseareshown.
Chunk Options
Forplots:fig.heightandfig.widthcontrolthesizeoftheplot,andfig.aligncontrols
itsposiCon
Inline CodeToday is`r Sys.Date()`.
Today is 2018-02-06.
Placecodeinasentencewith`r#code`.RMarkdownwillreplacethecodewithitsresults.
Output Format
Preview
WhilewriCngyourdocument,youcanperiodicallyPreviewit.
Knit Youcanknittohtml,pdf,orwordbyclicking
onthetriangle
YAML Header
TheYAMLheaderkeepstrackoftheoutputtypes
andtheiropCons
YAML Header
IftheabilitytoPreviewthenotebookdisappears,addthislinetotheYAML
The setup code chunk
Chunk OptionsThesetupcodechunkisalwaysrunonce
beforeanyotherchunks.Inthiscourse,thiswillbethefirstcodechunkthatwillcontainthepackagesyouareusing.Youcanhidethewarningsandmessagesforloadingpackages
Eventually…
Interactive Webpages
Websites
Books
Journal Articles