I have a code chunk in a .Rnw file like this:

<<test, results = "asis">>=

stargazer(mtcars, notes = c($n$ = \\Sexpr{nrow(mtcars)})

@

When I use knitr to evaluate the R code and convert the .Rnw file to a .tex file, how can I get nrow(mtcars) to evaluate?

有帮助吗?

解决方案

I believe you want something like this:

\documentclass{article}

\begin{document}

<<test, results = "asis">>=
library("stargazer")
stargazer(mtcars, notes = paste('$n$ = ',nrow(mtcars)))
@

\end{document}

You can't put an Sexpr inside a code chunk.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top