Merck / r2rtf

Easily Create Production-Ready Rich Text Format (RTF) Table and Figure
https://merck.github.io/r2rtf
GNU General Public License v3.0
76 stars 19 forks source link

Is it possible to add a long free text? #204

Closed schenexel closed 11 months ago

schenexel commented 11 months ago

Question Is it possible to add a long free text below the table generated by r2rtf?

Thanks in advance!

elong0527 commented 11 months ago

Check as_table argument in rtf_footnote and rtf_source if you want the text right after the table.

If you want the text at the end of each page, check rtf_page_footer

schenexel commented 11 months ago

Check as_table argument in rtf_footnote and rtf_source if you want the text right after the table.

If you want the text at the end of each page, check rtf_page_footer

Thanks for the suggestion, elong! What I need is a multi-page long narrative of the table content. And I have tested rtf_footnote and rtf_source, seems they change lines when I have either 'Enter' or '\n' in the text, which means I need to change lines in my program manually. Is there a way to let the program decide where to change lines based on the page width setting? Do you think there is a function that can do this multi-page free text?

elong0527 commented 11 months ago

Could you provide a screenshot or reproducible code to show what you want to achieve?

If you want to remove "\n" after typing enter, you may use the gsub function or other string replacement functions in R.

schenexel commented 11 months ago

Hi elong, I need something like r2rtf:::rtf_paragraph on https://merck.github.io/r2rtf/articles/rtf-text.html, but looks like it's deprecated now.

please see the example of what I need below.

library(r2rtf)
library(ggplot2)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(tidyr)

tbl <- r2rtf_adae %>%
  count(TRTA, AEDECOD) %>%
  pivot_wider(names_from = TRTA, values_from = n, values_fill = 0)

head(tbl) %>%
  rtf_body() %>% # Step 1 Add table  attributes
  rtf_encode() %>% # Step 2 Convert attributes to RTF encode
  write_rtf("output/intro-ae1.rtf")
#> Warning in file(file, ifelse(append, "a", "w")): cannot open file
#> 'output/intro-ae1.rtf': No such file or directory
#> Error in file(file, ifelse(append, "a", "w")): cannot open the connection

Created on 2023-10-19 with reprex v2.0.2 If I want to add the following text to right below the table generated by above code, what should I do? And I need change line automatically, not by using neither Enter or '\n'. Thank you!

Text:

"Overview r2rtf is an R package to create production ready tables and figures in RTF format. The R package is designed to

provide simple “verb” functions that correspond to each component of a table, to help you translate data frame to table in RTF file. enable pipes (%>%). only focus on table format. Data manipulation and analysis should be handled by other R packages. (e.g., tidyverse) r2rtf minimizes package dependency Before creating an RTF table we need to:

Figure out table layout. Split the layout into small tasks in the form of a computer program. Execute the program. This document introduces r2rtf basic set of tools, and show how to transfer data frames into Table, Listing, and Figure (TLFs).

Other extended examples and features are covered in different document listed in vignettes.

Data: Adverse Events To explore the basic RTF generation verbs in r2rtf, we will use the dataset r2rtf_adae. This dataset contain adverse events (AE) information from a clinical trial.

Below is the meaning of relevant variables. More information can be found in help page of the dataset (?r2rtf_adae)

USUBJID: Unique Subject Identifier TRTA: Actual Treatment AEDECOD: Dictionary-Derived Term"

elong0527 commented 11 months ago

Feel you want to write multiple paragraphs after a table.

r2rtf focus on format within a table.

We typically assemble tables and paragraphs for a clinical study report using the toggle fields feature in Word.

https://r4csr.org/tlf-assemble.html#using-toggle-fields