Sharedlatex-tests / system.rnwOpen in CoCalc
\documentclass{article}
\usepackage[utf8]{inputenc}

\title{knitr-test}
\author{Harald Schilly}
\date{July 2018}

\begin{document}

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-')
@

<<cache=TRUE>>=
# Create a sequence of numbers
X = 2:10

# Display basic statistical measures
summary(X)
@

t

t

t

t

t

t

<<cache=TRUE>>=
fileConn<-file("data.txt")
writeLines(paste(c(1:10), collapse=", "), fileConn)
close(fileConn)
@

and output

<<cache=TRUE>>=
fileConn <- file("data.txt")
data <- readLines(fileConn)
message(data)
@

data: \Sexpr{data}.

t

<<cache=TRUE>>=
system("mount", intern = TRUE)
@


<<cache=TRUE>>=
system("hostname", intern = TRUE)
@

<<cache=TRUE>>=
system("cat /etc/os-release", intern = TRUE)
@


<<>>=
system("ls -la", intern = TRUE)
@

<<>>=
system("ls -la .cache/clsi/*", intern = TRUE)
@


%/usr/lib/R/bin/exec/R --slave --no-restore -e %library('knitr');~+~setwd('/compile');~+~knit('main.Rtex')"

<<>>=
system("cat .project-sync-state", intern = TRUE)
@

<<>>=
system("ps aux", intern = TRUE)
@

ok

t
t

t

t

t

t
t

t
ok

<<echo=FALSE>>=
n <- 0
@

<<>>=
n <- n + 0
Sys.sleep(0)
message(cat(n, "secs later"))
@




t

t

ok

t
t

t

t

t

t

ok

t
t

t

t

t

t

ok

t
t

t

t

t

t

ok

t
t

t

t

t

t

ok

t

t

t

t

t


<<>>=
message(1:10)
@

ok

t

t

t

t

t


<<>>=
message(1:10)
@

ok

t

t

t

t

t


<<>>=
message(1:10)
@

ok

t

t

t

t

t


<<>>=
message(1:10)
@



\end{document}