How to display pre-defined variable labels in table headers using r2rtf package

With the below codes, it is producing a table in rtf format with variable names rather than the labels (see screenshot at the bottom of the page). Is there a way I could read in the existing variable labels rather than manually entering the labels one by one?


listing01 %>%
orientation = "landscape"
) %>%
title = c(
"Listing 1",
"Enrolment, Randomisation and Completion / Discontinuation"),
text_font_size = 8
) %>%
rtf_colheader( ) %>% # NEED TO ADD VARIABLE LABELS PRE-DEFINED IN "listings_01" dataset
col_rel_width = c(3, rep(3, 6)),
text_justification = "c",
text_font_size = 8,
border_left = "",
border_right = "",
border_top = "",
border_bottom = ""
) %>%

rtf_footnote() %>%

rtf_encode() %>%
write_rtf(file = "01_Listings_Enrolment_Randomisation_and_Completion_Discontinuation.rtf")

Just adding the snip of the rtf output:

label is saved as an attribute of each variable. You just need to extract them and reorganize them into rtf_colheader.

For example:

paste(sapply(listing01, attr, "label"), collapse = "|")

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.