Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 2218
1
\documentclass{article}
2
\usepackage[utf8]{inputenc}
3
\usepackage[T1]{fontenc}
4
\usepackage{url}
5
\begin{document}
6
7
% learn more about knitr: https://yihui.name/knitr/
8
9
<<setup, include=FALSE, cache=FALSE, echo = FALSE>>=
10
library(knitr)
11
library(pander)
12
opts_chunk$set(cache=TRUE, autodep=TRUE)
13
options(formatR.arrow=TRUE, width=90)
14
@
15
16
\title{Knitr dans CoCalc}
17
18
\author{Juanito Alima\~na}
19
20
\maketitle
21
22
Comme SageTeX, mais avec R. Le principe est essentiellement le même.
23
24
\medskip
25
26
\begin{center}
27
<<summary, echo = FALSE>>=
28
library(knitr)
29
x <- c(2,3,4,5,1,2,3,2,1)
30
kable(as.matrix(summary(x)))
31
@
32
\end{center}
33
34
\begin{figure}[h!]
35
\centering
36
<<histogram-plot, echo = F,fig.width=4, fig.height=4, out.width='.4\\linewidth'>>=
37
hist(x)
38
@
39
\caption{Voici l'histogramme}
40
\end{figure}
41
42
Sum of \Sexpr{paste(x, collapse=" + ")} is \Sexpr{sum(x)}.
43
44
\medskip
45
46
Voyons une tableau
47
48
49
<<kable, echo = FALSE>>=
50
n <- 100
51
x <- rnorm(n)
52
y <- 2*x + rnorm(n)
53
out <- lm(y ~ x)
54
library(knitr)
55
kable(summary(out)$coef, digits=2)
56
@
57
58
\end{document}
59
60
61
62