Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process for including a list-column with gt, ggplot2, or other non-strings in vectorized epoxy chunk #129

Open
elipousson opened this issue Nov 13, 2024 · 2 comments

Comments

@elipousson
Copy link

I am using epoxy to produce a report that includes text elements mixed in with tables. The vectorized inline reporting chunks are really useful for the text elements and I'm interested in using the same approach to include the gt tables or plots created with ggplot2.

Is there a recommended process for customizing epoxy for this type of use?

I looked (but have not yet tried) using the transformer argument to customize the formatting of gt objects (or other elements). However, I was unsure how to keep the default transformer in place and add instead of replace the available inline transformers.

Thanks for the package and any additional tips you can share!

@elipousson
Copy link
Author

I took a closer look at the documentation and figured this out that works for both gt tables and list columns containing gt table objects (I think):

knitr::opts_chunk$set(
  .transformer = epoxy_transform_inline(
    .gt = \(x) {
      if (inherits(x, "gt_tbl")) {
        return(knitr::knit_print(x))
      }
      
      lapply(x, knitr::knit_print)
    },
  )
)

I didn't realize initially that I could set additional transformation options with epoxy_transform_inline() without over-writing all of the built-in styles.

@gadenbuie
Copy link
Owner

Nice! Also you can use epoxy_transform_set() to define the .gt inline transformer.

epoxy_transform_set(
  .gt = \(x) {
    if (inherits(x, "gt_tbl")) {
      return(knitr::knit_print(x))
    }
    
    lapply(x, knitr::knit_print)
  },
)

Of course, as I'm looking at this snippet, I think maybe epoxy could handle calling knit_print() or at least could provide a .knit_print transformer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants