Skip to content

Add support for figures #86

Closed
Closed

Description

@mstackhouse

Expand clinify to support addition of figures into the output.

Activity

  1. mattkumar commented on Jul 2, 2025

    @mattkumar

    Just what I was wondering... :)

    We're using clinify in making a small results package for a study / pilot, some of the results will be generated by ggplot as well.

    I've tried to first generate the document, read it back in with officer, append an image with officer and write it back.

    doc2 <- read_docx("clinify_output.docx")
    doc2 <- body_add_gg(doc2, value = my_awesome_plot, width = 10, height = 7, res = 300)
    print(doc2, target = "final_output.docx")
    

    I get an error that occurs while printing the final docx:

    Error in data.frame(content_section = content_section_chrs, file_name = file_names, : arguments imply differing number of rows: 0, 1

    I need to take a closer look at my workflow (its super hacky atm), but if it's helpful I'm using as_clintable(), write_clintable() and clin_add_titles() so far in my script.

    Also: Hope you've been keeping well man, it's been a while!

  2. mstackhouse commented on Jul 21, 2025

    @mstackhouse
    MemberAuthor

    Interestingly, this only happens if titles and footnotes are set:

    library(clinify)
    library(ggplot2)
    
    ct1 <- clintable(head(iris)) 
    ct2 <- clintable(head(iris)) |>
      clin_add_titles("title")
    
    # Basic scatter plot
    plt <- ggplot(mtcars, aes(x = wt, y = mpg)) +
      geom_point() +
      labs(title = "Car Weight vs MPG",
          x = "Weight (1000 lbs)",
          y = "Miles per Gallon")
    
    # Works
    write_clindoc(ct1, "~/Downloads/works.docx")
    docx <- officer::read_docx("~/Downloads/works.docx")
    docx2 <- officer::body_add_gg(docx, value = plt, width = 10, height = 7, res = 300)
    print(docx2, target = "~/Downloads/works_with_plot.docx")
    
    # Doesn't work
    write_clindoc(ct2, "~/Downloads/breaks.docx")
    docx <- officer::read_docx("~/Downloads/breaks.docx")
    docx2 <- officer::body_add_gg(docx, value = plt, width = 10, height = 7, res = 300)
    print(docx2, target = "~/Downloads/breaks_with_plot.docx")
    #> Error in data.frame(content_section = content_section_chrs, file_name = file_names, : arguments imply differing number of rows: 0, 1

    Created on 2025-07-21 with reprex v2.1.1

    That said, I don't think this approach would even solve the underlying issue (easily), because the tabels still writes to the body, and right now you can't write a document out without one.

    I think a proper implementation of this should be reasonably straightforward though. Tables have a lot of pagination concerns. Plots should realistically be one plot object per page. So the flow could be:

    • Create a list of plots
    • Add list of plots to clindoc()
    • Page break between each element passed to clindoc().

    Hope you're doing well too, @mattkumar! Thanks for always being an early package tester here!

  3. mstackhouse commented on Jan 7, 2026

    @mstackhouse
    MemberAuthor

    @mattkumar check out #92 because apparently this is possible and I just didn't realize how.

  4. mstackhouse commented on Nov 4, 2026

    @mstackhouse
    MemberAuthor

    Closed with #92

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions