Can' create LaTex etable on R Markdown

Hi, i'm new to markdown, so this is difficult to me. I'm working with feols function from the package "fixest" to estimate a fixed effects model. My code runs fine in R scrip and rmd, but when I try etable to export my results I only get Latex code. My code looks something like this (here I use airquality as an example):

---
title: "Untitled"
author: "me"
date: '2022-07-16'
output:
  pdf_document: default
  html_document: default
---
{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
{r}
library(fixest)
library(tinytex)

est1 = feols(Ozone ~ i(Month) / Wind + Temp, data = airquality)
est2 = feols(Ozone ~ i(Month, Wind) + Temp | Month, data = airquality)

etable(est1,est2, tex = T)

I do not have MikTex installed, but I have Tinitex, using:

install.packages('tinytex')
tinytex::install_tinytex()

I would greatly appreciate your help.
P.D. I have the newest version of R.

The statement etable(est1,est2, tex = T) generates LaTeX code .
With the chunk option results='asis' you should indicate that
you want to include that 'as it is' in the tex intermediary file.

When I did this I got an error that the midrule command could not be found.
Google search told me that midrule belongs to the booktabs package
Therefore I added extra_dependencies: ["booktabs"] in the YAML to generate \usepackage{booktabs} ,
but there are other ways to add to the preamble. See e.g.
https://bookdown.org/yihui/rmarkdown-cookbook/latex-preamble.html

The full Rmd file then looks like this (I enclosed it in four backticks to show the three backticks :grinning: ) :

---
title: "Untitled"
author: "me"
date: '2022-07-16'
output:
  pdf_document: 
    extra_dependencies: ["booktabs"]
    keep_tex: TRUE
  html_document: default
---
    
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r}
library(fixest)
# library(tinytex) # not necessary after install tinytex

est1 = feols(Ozone ~ i(Month) / Wind + Temp, data = airquality)
est2 = feols(Ozone ~ i(Month, Wind) + Temp | Month, data = airquality)
```

```{r results='asis'}
etable(est1,est2, tex = T)
```
2 Likes

It worked perfectly. I was really worried about this rmd and i was thinking in reinstalling R :sweat_smile:,
again, thank u :smiley:

1 Like

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it: