Search code examples
rquarto

I am unable to add table caption to some of the tables in a quarto web page in R


I am trying to create a quarto web page. In this web page, I am unable to get table caption for some of the tables. In particular, this happens when the {easystats} package is involved.

```{r}
library(easystats)
library(broom)
```

Then I am creating a regression model using the mtcars dataset.

```{r}
lm_model <- lm(mpg~cyl+drat, data = mtcars)
```

Now I am trying to create table of regression information.

```{r}
#| tbl-cap: "Easystats"
#| label: tbl-easystats
model_parameters(lm_model)
```

Another way to extract same info using {broom} package.

```{r}
#| tbl-cap: "Broom"
#| label: tbl-broom
tidy(lm_model)
```

Out of these two, the "Broom" table gets the caption when I render the document, but the "Easystats" package doesn't get the caption. In the place of the caption, it shows ?Caption. Is it something to do with the easystats package or is there some other issue?

Created on 2023-01-08 with reprex v2.0.2


Solution

  • From ?model_parameters,

    The print() method (i.e. print.parameters_model) has several arguments to tweak the output.

    and a dedicated method for use inside rmarkdown files, print_md().

    Also there is a print_html() function too. So you can pass the output of model_parameters(lm_model) to either print_md() or print_html().

    ---
    title: "Table Cap"
    format: html
    ---
    
    ## Easystats in Quarto
    
    ```{r}
    #| message: false
    library(easystats)
    lm_model <- lm(mpg~cyl+drat, data = mtcars)
    ```
    
    ```{r}
    #| tbl-cap: "Easystats 01"
    #| label: tbl-easystats01
    model_parameters(lm_model) |> print_md()
    ```
    
    ```{r}
    #| tbl-cap: "Easystats 02"
    #| label: tbl-easystats02
    model_parameters(lm_model) |> print_html()
    ```
    

    EasyStats in Quarto