leifeld / texreg

Conversion of R Regression Output to LaTeX or HTML Tables
110 stars 42 forks source link

Quarto integration? #190

Open AaronGullickson opened 2 years ago

AaronGullickson commented 2 years ago

Hello, I am a big fan of texreg and, in particular, the knitreg function that works so well in R Markdown. I am wondering if there are any plans to work on integration with Quarto, the "next-gen" version of R Markdown? I have been playing around with Quarto a bit and I have noticed that while texreg generally plays well with Quarto, there are a couple of issues. Namely:

leifeld commented 2 years ago

I am embarrassed to say that I've been completely unaware of Quarto. If you'd like to start a pull request and make suggestions on how to change the knitreg function, I would be happy to review the PR and provide advice. Not sure if it makes more sense to accommodate the functionality in knitreg or create a new quartoreg function. I'd assume the latter, but don't know anything about the differences between the two systems. If there is no pull request, I might get to it at some point when I see the need for myself or if a lot of people request this.

AaronGullickson commented 2 years ago

No worries. I will see if I can figure out some of this stuff and if so I will put up a PR.

AaronGullickson commented 1 year ago

Ok, coming back to this after awhile, but I am going to try to write a PR that adds a quartoreg function that operates similarly toknitreg but for Quarto docs. I am writing some notes to myself here so I remember this stuff.

Basically, the issue is how to get the rendering format so quartoreg knows what kind of code to output. Looking through the code for gt, and found this which I think is helpful:

if (knitr_is_rtf_output()) {

    # TODO: make this work for RTF
    x <- as_rtf(x)

  } else if (knitr::is_latex_output()) {

    # TODO: make this work for LaTeX
    x <- as_latex(x)

  } else if (knitr_is_word_output()) {

    word_tbls <- c()

    seq_tbls <- seq_len(nrow(x$gt_tbls))

    for (i in seq_tbls) {
      word_tbl_i <- as_word(grp_pull(x, which = i))
      word_tbls <- c(word_tbls, word_tbl_i)
    }

    word_tbls_combined <- paste(word_tbls, collapse = page_break_word())

    x <-
      knitr::asis_output(
        paste("```{=openxml}", word_tbls_combined, "```\n\n", sep = "\n")
      )

  } else {

    # TODO: make this work for HTML

    # Default to HTML output
    x <- as.tags.gt_tbl(x, ...)
  }
knitr_is_rtf_output <- function() {
  "rtf" %in% knitr::opts_knit$get("rmarkdown.pandoc.to")
}

knitr_is_word_output <- function() {
  "docx" %in% knitr::opts_knit$get("rmarkdown.pandoc.to")
}