Communication Flashcards
What is the diff btw R markdown and R notebook?
R notebook files show the output of code chunks inside the editor, while hiding the console, when they are edited in RStudio. This contrasts with R markdown files, which show their output inside the console, and do not show output inside the editor. This makes R notebook documents appealing for interactive exploration.
R markdown files can be knit to a variety of formats including HTML, PDF, and DOCX. R notebooks can only be knit to HTML, with the extension .nb.html. The output of an R notebook keeps a copy of the original .Rmd source. If a .nb.html file is opened in RStudio, the source of the .Rmd file can be extracted and edited. In contrast, there is no way to recover the original source of an R markdown file from its output, except through the parts that are displayed in the output itself.
R markdown files and R notebooks differ in the value of output in their YAML headers
ouptut: html_notebook
- –
while for R markdwon is ouptut: html_document
Rnotebook have preview option while Rmarkdwon does not have preview option only knit
more here : https://stackoverflow.com/questions/43820483/difference-between-r-markdown-and-r-notebook/43898504#43898504
What will happned if you change the rnotebook YAML header with r markdwon heder?
Copying the YAML header from an R notebook to a R markdown file changes it to an R notebook, and vice-versa. More specifically, an .Rmd file can be changed to R markdown file or R notebook by changing the value of the output key in the header.
The RStudio IDE and the rmarkdown package both use the YAML header of an .Rmd file to determine the document-type of the file.
Knitr shorcut ?
Cmd/Ctrl + Alt + K.
What is out YML header for PDF , HTML , Word?
output: pdf_document , output: html_document , output: word_document , pdf_document: default
How to format text in R markdown?
italic or italic
bold __bold__code
superscript^2^ and subscript~2~
how to form heading in R markdown?
1st Level Header
2nd Level Header
3rd Level Header
.
How to make list in R markdown?
- Bulleted list item 1
- Item 2
- Item 2a
- Item 2b
- Numbered list item 1
- Item 2. The numbers are incremented automatically in the output
Insert code chunk, 3 ways?
- Cmd/Ctrl + Alt + I
- The “Insert” button icon in the editor toolbar.
- By manually typing the chunk delimiters
{r} and
.
chunk/run code in markdwon?
Cmd/Ctrl + Shift + Enter, which runs all the code in the chunk
Chunk has a name. how can we create name for chunk?
Chunks can be given an optional name: ```{r by-name}. This has three advantages:
- You can more easily navigate to specific chunks using the drop-down code navigator in the bottom-left of the script editor:
- Graphics produced by the chunks will have useful names that make them easier to use elsewhere.
- You can set up networks of cached chunks to avoid re-performing expensive computations on every run.
Chunk has option. What are they usfeul for ?
Chunk output can be customised with options, arguments supplied to chunk header. Knitr provides almost 60 options that you can use to customize your code chunks.
Chunk option eval = FALSE . what does this means?
eval = FALSE prevents code from being evaluated. (And obviously if the code is not run, no results will be generated). This is useful for displaying example code, or for disabling a large block of code without commenting each line.
Include = FALSE chunk option?
Include = FALSE runs the code, but doesn’t show the code or results in the final document. Use this for setup code that you don’t want cluttering your report.
echo= FALSE, chunk option?
echo = FALSE prevents code, but not the results from appearing in the finished file. Use this when writing reports aimed at people who don’t want to see the underlying R code.
message= FALSE , what does it mean? . the chunk options are all True by default
message = FALSE or warning = FALSE prevents messages or warnings from appearing in the finished file.
result = hide?
results = ‘hide’ hides printed output; fig.show = ‘hide’ hides plots.
error = TRUE
error = TRUE causes the render to continue even if code returns an error. This is rarely something you’ll want to include in the final version of your report, but can be very useful if you need to debug exactly what is going on inside your .Rmd. It’s also useful if you’re teaching R and want to deliberately include an error. The default, error = FALSE causes knitting to fail if there is a single error in the document.
How to use Table in Rmarkdwon?
By default, R Markdown prints data frames and matrices as you’d see them in the console:
If you prefer that data be displayed with additional formatting you can use the knitr::kable function. The code below generates Table 27.1.
knitr::kable(
mtcars[1:5, ],
caption = “A knitr kable.”
)