Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Knitr Reference Card Cheat Sheet, Cheat Sheet of Advanced Computer Programming

kinter and markdown cheat sheet

Typology: Cheat Sheet

2020/2021

Uploaded on 04/23/2021

hardcover
hardcover 🇺🇸

4.7

(7)

259 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
knitr Reference Card
Yihui Xie
January 27, 2021
1 Syntax
format start end inline output
Rnw
<<*>>= @ \Sexpr{x}
T
EX
Rmd
```
{r *}
``` `
r x
`
MD
Rhtml
<!--begin.rcode * end.rcode--> <!--rinline x-->
HTML
Rrst
.. {r *} .. .. :r:
`
x
`
reST
Rtex
% begin.rcode * % end.rcode \rinline{x}
T
EX
Rasciidoc
// begin.rcode * // end.rcode +r x+
AsciiDoc
Rtextile
### begin.rcode * ### end.rcode @r x@
Textile
brew
<% x %>
text
*
denotes local chunk options, e.g.
<<label, eval=FALSE>>=
;
x
denotes inline R
code, e.g.
`
r 1+2
`
(MD stands for Markdown)
2 Minimal Examples
2.1 Sweave (*.Rnw)
\documentclass{article}
\begin{document}
Below is a code chunk.
<<foo, echo=TRUE>>=
z = 1+1
plot(cars)
@
The value of z is \Sexpr{z}.
\end{document}
2.2 R Markdown (*.Rmd)
Hi _markdown_!
```
{r foo, echo=TRUE}
z = 1+1
plot(cars)
```
The value of z is
`
r z
`
.
2.3 Brew (*.brew)
The value of pi is <% pi %>.
3 Chunk Options
opts_chunk
controls global chunk options, e.g.
opts_chunk$set(tidy = FALSE)
,
which can be overridden by local chunk options. See all options at
https:
//yihui.org/knitr/options/
; some frequently used options:
eval
whether to evaluate the chunk
echo
whether to echo source code
results
'
markup
'
,
'
asis
'
,
'
hold
'
,
'
hide
'
tidy
whether to reformat R code
cache
whether to cache results
g.width, g.height, out.width, out.height
device and output size of gures
include
whether to include the chunk results in output
child
lenames of child documents
engine
language name (R, python, .. . )
4 Functions
knit()
the main function in this package; knit input document and write output
purl()
extract R code from an input document
spin()
spin goat's hair (an R script with roxygen comments) into wool (a literate
programming document to be passed to
knit()
)
stitch()
insert an R script into a template and compile the document
knit_hooks$set()
set or reset chunk and output hooks
5 Resources
homepage:
https://yihui.org/knitr/
development repository:
https://github.com/yihui/knitr
(CRAN,
examples:
https://github.com/yihui/knitr-examples
stackoverow:
http://stackoverflow.com/tags/knitr/
mailing list:
https://groups.google.com/group/knitr
1

Partial preview of the text

Download Knitr Reference Card Cheat Sheet and more Cheat Sheet Advanced Computer Programming in PDF only on Docsity!

knitr Reference Card

Yihui Xie

January 27, 2021

1 Syntax

format start end inline output Rnw <<*>>= @ \Sexpr{x} TEX Rmd {r *} r x MD Rhtml HTML Rrst .. {r *} .. .. :r:x reST Rtex % begin.rcode * % end.rcode \rinline{x} TEX Rasciidoc // begin.rcode * // end.rcode +r x+ AsciiDoc Rtextile ### begin.rcode * ### end.rcode @r x@ Textile brew <% x %> text

  • denotes local chunk options, e.g. <<label, eval=FALSE>>=; x denotes inline R code, e.g. r 1+2 (MD stands for Markdown)

2 Minimal Examples

2.1 Sweave (*.Rnw)

\documentclass{article} \begin{document}

Below is a code chunk. <<foo, echo=TRUE>>= z = 1+ plot(cars) @

The value of z is \Sexpr{z}. \end{document}

2.2 R Markdown (*.Rmd)

Hi markdown!

z = 1+ plot(cars) 

The value of z is r z.

2.3 Brew (*.brew)

The value of pi is <% pi %>.

3 Chunk Options

opts_chunk controls global chunk options, e.g. opts_chunk$set(tidy = FALSE), which can be overridden by local chunk options. See all options at https: //yihui.org/knitr/options/; some frequently used options:

eval whether to evaluate the chunk echo whether to echo source code results 'markup', 'asis', 'hold', 'hide' tidy whether to reformat R code cache whether to cache results g.width, g.height, out.width, out.height device and output size of gures include whether to include the chunk results in output child lenames of child documents engine language name (R, python,... )

4 Functions

knit() the main function in this package; knit input document and write output purl() extract R code from an input document spin() spin goat's hair (an R script with roxygen comments) into wool (a literate programming document to be passed to knit()) stitch() insert an R script into a template and compile the document knit_hooks$set() set or reset chunk and output hooks

5 Resources

ˆ homepage: https://yihui.org/knitr/ ˆ development repository: https://github.com/yihui/knitr (CRAN, ˆ examples: https://github.com/yihui/knitr-examples ˆ stackoverow: http://stackoverflow.com/tags/knitr/ ˆ mailing list: https://groups.google.com/group/knitr