I have an R function which returns a latex fragment, which I'd like to insert into my org file. Here's what I tried, which just inserts the latex source:
#+BEGIN_SRC R :exports none :results silent
data(cars)
fitted <- lm(dist ~ speed, data=cars)
library(stargazer)
stargazer(fitted, out='fitted.tex')
#+END_SRC
#+INCLUDE: "fitted.tex" src latex
The latex output renders fine if I manually paste it into the org file between #+BEGIN_LATEX
and #+END_LATEX
markers.
Here it is for reference:
% Table created by stargazer v.5.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
% Date and time: Wed, Mar 28, 2018 - 04:44:03 PM
\begin{table}[!htbp] \centering
\caption{}
\label{}
\begin{tabular}{@{\extracolsep{5pt}}lc}
\\[-1.8ex]\hline
\hline \\[-1.8ex]
& \multicolumn{1}{c}{\textit{Dependent variable:}} \\
\cline{2-2}
\\[-1.8ex] & dist \\
\hline \\[-1.8ex]
speed & 3.932$^{***}$ \\
& (0.416) \\
& \\
Constant & $-$17.579$^{**}$ \\
& (6.758) \\
& \\
\hline \\[-1.8ex]
Observations & 50 \\
R$^{2}$ & 0.651 \\
Adjusted R$^{2}$ & 0.644 \\
Residual Std. Error & 15.380 (df = 48) \\
F Statistic & 89.567$^{***}$ (df = 1; 48) \\
\hline
\hline \\[-1.8ex]
\textit{Note:} & \multicolumn{1}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\
\end{tabular}
\end{table}
stdout
instead of the.tex
file. The results would then show up in a#+RESULTS:
block after yourSRC
block, and you could then:exports results
in yourSRC
block header. No external file is cleaner.