'How to combine 2 RTF files in R

I'm unable to combine 2 or more RTF files in R. Anybody who knows please help me out. I'm trying to add footnotes for the rtf files but they are not taking it.

table_rtf <- uu_all %>%
    rtf_page(orientation = "landscape") %>%
    rtf_title(title = "Table 3.1.1: TWHS AF (Visual) - Descriptive Statistics - Raw Values", text_format = "b", text_font_size = 14) %>%
    
    rtf_colheader(colheader = " TIMEPOINT | STATISTIC | EL9 | KC8 | MG6", 
                  col_rel_width = c(2.8,2.8,2.5,2.5,2.5), text_format = "b") %>%
    
    rtf_body( col_rel_width = c(2.8,2.8,2.5,2.5,2.5),
              text_justification = c("l", "l", rep("c",3)),
              group_by="Timepoint") %>%
    rtf_footnote("N=Number of Observations; Min=Minimum; Max=Maximum; SD=Standard Deviation; SE=Standard Error; CI=Confidence Interval")  

I have a similar second table. But the footnotes are not picked up. It retains the footnote of the first table. Hence i decided to prepare 2 seperate rtf files and merge them. Can anyone tell me how to merge 2 rtf files in r. Thanks in advance.



Solution 1:[1]

I had a same condition where I was required to combine multiple rtf files generated . So, I found you can easily append the rtf files before encoding. append two files in a list

apend <- list(table_rtf, table_rtf)

## now encode and write the file

apend %>%
 rtf_encode() %>%
 write_rtf("a.rtf")

Another option is to use encoded table and append the body section of each table

    rtf_page(orientation = "landscape") %>%
    rtf_title(title = "Table 3.1.1: TWHS AF (Visual) - Descriptive Statistics - Raw Values", text_format = "b", text_font_size = 14) %>%
    
    rtf_colheader(colheader = " TIMEPOINT | STATISTIC | EL9 | KC8 | MG6", 
                  col_rel_width = c(2.8,2.8,2.5,2.5,2.5), text_format = "b") %>%
    
    rtf_body( col_rel_width = c(2.8,2.8,2.5,2.5,2.5),
              text_justification = c("l", "l", rep("c",3)),
              group_by="Timepoint") %>%
    rtf_footnote("N=Number of Observations; Min=Minimum; Max=Maximum; SD=Standard Deviation; SE=Standard Error; CI=Confidence Interval")  %>%
rtf_encode()

now ,

table_rtf$ body and table_2_rtf$ body can be appended

and final will be

table_
final <- list( "start" = table_rtf$start ,"body"=table_rtf$body + table_2_rtf$body, "end" = table_rtf$end)

final %>%
   write_rtf("final.rtf")


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Adarsha regmi