\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{url}
\usepackage{graphicx}
\newcommand{\rinline}[1]{SOMETHING WRONG WITH knitr}
%% begin.rcode setup, include=FALSE
% library(knitr)
% opts_chunk$set(fig.path='figure/latex-', cache.path='cache/latex-')
%% end.rcode
\begin{document}
\title{Rtex Knitr in CoCalc}
\author{Author Name}
\maketitle
Boring stuff as usual:
%% begin.rcode
% 1+1
%
% x=rnorm(5); t(x)
%% end.rcode
For the cached chunk below, you will need to wait for 3 seconds for
the first time you compile this document, but it takes no time the
next time you run it again.
%% begin.rcode my-cache, cache=TRUE
% set.seed(123)
% x = runif(10)
% sd(x)
%
% Sys.sleep(3)
%% end.rcode
Now we know the first element of x is \rinline{x[1]}.
And we also know the 26 letters are \rinline{LETTERS}.
An expression that returns a value of length 0 will be removed from the output, \rinline{x[1] = 2011; NULL} but it was indeed evaluated,
i.~e. now the first element of x becomes \rinline{x[1]}.
How about figures? Let's use the Cairo PDF device (assumes R $\geq$ 2.14.0).
%% begin.rcode cairo-scatter, dev='cairo_pdf', fig.width=5, fig.height=5, out.width='.8\\textwidth'
% plot(cars)
%% end.rcode
Warnings, messages and errors are preserved by default.
%% begin.rcode
% sqrt(-1)
% message('this is a message you should know')
% 1+'a'
%% end.rcode
\end{document}