\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{url}
\title{Knitr in CoCalc}
\author{Harald Schilly}
\begin{document}
\maketitle
You can type R commands in your \LaTeX{} document and they will be properly run and the output printed in the document.
<<>>=
library(knitr)
opts_chunk$set(fig.path='figure/latex-', cache.path='cache/latex-')
@
<<>>=
R.version
@
<<>>=
ip <- installed.packages()
dim(ip)
@
<<cache=TRUE>>=
X = 2:10
summary(X)
@
<<>>=
myF <- function(x) {
print(2*x + 1)
}
myF(22)
@
$$x^y$$
<<>>=
a <- 111
@
<<>>=
x <- c(2,3,4,5,1,2,3,2)
summary(x)
@
<<histogram-plot, fig.width=6, fig.height=4, out.width='.75\\linewidth'>>=
hist(x)
@
Sum of \Sexpr{paste(x, collapse="+")} is \Sexpr{sum(x)}.
test
test 123
test
test
test
test
test
test
test
test
test
test
test
test
test
where am I? here.
t
t
t
asdf
t
t
t
t
t
t
t
t
t
t
123
t
this line
t
t
t
<<histogram-plot2, fig.width=8, fig.height=4, out.width='.4\\linewidth'>>=
hist(x)
@
t
t
t
ok
t
t
t
t
t
t
<<histogram-plot3, fig.width=4, fig.height=4, out.width='.4\\linewidth'>>=
hist(x)
@
t
t
t
t
t
t
t
t
t
\pagebreak
<<histogram-plot4, dev='tikz', fig.height=4, fig.width=10, out.width='.9\\linewidth'>>=
data <- rnorm(1000)
hist(data)
@
\Sexpr{1/17} and \Sexpr{1.23e-6}.
EOF
\end{document}