Adam C
Adam C

Reputation: 334

texreg output with RStudio and rmarkdown

I have a question that seems so simple and fundamental that I can't find the solution online. How do I make knitr (or Pandoc) evaluate the output given by the texreg functions?

A minimal example:

My entire .rmd file code:

---
title: "test texreg"
output: pdf_document
date: "January 27, 2016"
---

```{r}
library(texreg)
texreg(list(lm(speed~dist,data=cars)))
```

When I click Knit PDF (or Knit HTML or Knit Word) I get LaTeX code for the table but each line starts with two pound symbols, i.e. the r output from the texreg() function as if I had run it at the console. I have the same issue if I use htmlreg()

I assume that I just have to put the function call somewhere else? I can't seem to figure it out...

This question (R markdown "texreg") seems to ask the exact same question but the answer is unhelpful to me.

Upvotes: 1

Views: 1420

Answers (1)

Adam C
Adam C

Reputation: 334

I am not sure if this is the most elegant solution to my problem but I did discover a solution: Put the call to texreg() into an inline r block like so:

```{r}
library(texreg)
```

`r texreg(list(lm(speed~dist,data=cars)))`

This produces the LaTeX output in such a way that Pandoc and now identify it an produce the LaTeX table.

I would be happy to accept more informed answers if they come along.

Edit:

Another option: add results="asis" to the code chunk header. I tried that originally but another error prevented me from seeing the correctly formatted table and consequently I didn't realize I had stumbled upon the solution.

Upvotes: 0

Related Questions