Title: | Easily Create Production-Ready Rich Text Format (RTF) Tables and Figures |
---|---|
Description: | Create production-ready Rich Text Format (RTF) tables and figures with flexible format. |
Authors: | Yilong Zhang [aut], Siruo Wang [aut], Simiao Ye [aut], Fansen Kong [aut], Brian Lang [aut], Benjamin Wang [aut, cre], Nan Xiao [ctb], Madhusudhan Ginnaram [ctb], Ruchitbhai Patel [ctb], Huei-Ling Chen [ctb], Peikun Wu [ctb], Uday Preetham Palukuru [ctb], Daniel Woodie [ctb], Sarad Nepal [ctb], Jane Liao [ctb], Jeff Cheng [ctb], Yirong Cao [ctb], Amin Shirazi [ctb], Yihui Xie [ctb], Günter Milde [ctb] (Original author of the unimathsymbols.txt file), Merck Sharp & Dohme Corp [cph] |
Maintainer: | Benjamin Wang <[email protected]> |
License: | GPL-3 |
Version: | 1.1.2 |
Built: | 2024-11-29 05:39:31 UTC |
Source: | https://github.com/Merck/r2rtf |
The function assemble multiple RTF table, listing, and figures into
one document as Microsoft Word (i.e., docx
).
assemble_docx(input, output, landscape = FALSE)
assemble_docx(input, output, landscape = FALSE)
input |
Character vector of file path. |
output |
Character string to the output file path. |
landscape |
Logical vector to determine page direction. |
The contents of this section are shown in PDF user manual only.
library(officer) library(magrittr) file <- replicate(2, tempfile(fileext = ".rtf")) file1 <- head(iris) %>% rtf_body() %>% rtf_encode() %>% write_rtf(file[1]) file2 <- head(cars) %>% rtf_page(orientation = "landscape") %>% rtf_body() %>% rtf_encode() %>% write_rtf(file[2]) output <- tempfile(fileext = ".docx") assemble_docx( input = file, output = output )
library(officer) library(magrittr) file <- replicate(2, tempfile(fileext = ".rtf")) file1 <- head(iris) %>% rtf_body() %>% rtf_encode() %>% write_rtf(file[1]) file2 <- head(cars) %>% rtf_page(orientation = "landscape") %>% rtf_body() %>% rtf_encode() %>% write_rtf(file[2]) output <- tempfile(fileext = ".docx") assemble_docx( input = file, output = output )
The function assemble multiple RTF table, listing, and figures into one document as RTF file.
assemble_rtf(input, output, landscape = FALSE)
assemble_rtf(input, output, landscape = FALSE)
input |
Character vector of file path. |
output |
Character string to the output file path. |
landscape |
Logical value to determine page direction. |
The contents of this section are shown in PDF user manual only.
library(magrittr) file <- replicate(2, tempfile(fileext = ".rtf")) file1 <- head(iris) %>% rtf_body() %>% rtf_encode() %>% write_rtf(file[1]) file2 <- head(cars) %>% rtf_page(orientation = "landscape") %>% rtf_body() %>% rtf_encode() %>% write_rtf(file[2]) output <- tempfile(fileext = ".rtf") assemble_rtf( input = file, output = output )
library(magrittr) file <- replicate(2, tempfile(fileext = ".rtf")) file1 <- head(iris) %>% rtf_body() %>% rtf_encode() %>% write_rtf(file[1]) file2 <- head(cars) %>% rtf_page(orientation = "landscape") %>% rtf_body() %>% rtf_encode() %>% write_rtf(file[2]) output <- tempfile(fileext = ".rtf") assemble_rtf( input = file, output = output )
A dataset containing the adverse event information of a clinical trial following CDISC ADaM standard.
r2rtf_adae
r2rtf_adae
A data frame with 1191 rows and 55 variables.
Definition of each variable can be found in https://github.com/phuse-org/phuse-scripts/tree/master/data/adam/cdisc
https://github.com/phuse-org/phuse-scripts/tree/master/data/adam/cdisc
A dataset containing the demographic information of a clinical trial following CDISC ADaM standard.
r2rtf_adsl
r2rtf_adsl
A data frame with 254 rows and 51 variables.
Definition of each variable can be found in https://github.com/phuse-org/phuse-scripts/tree/master/data/adam/cdisc
https://github.com/phuse-org/phuse-scripts/tree/master/data/adam/cdisc
A dataset prepared by the Drug Information Association scientific working group to investigate a drug to reduce lower back pain.
r2rtf_HAMD17
r2rtf_HAMD17
A data frame with 831 rows and 6 variables.
Definition of each variable can be found in https://www.lshtm.ac.uk/research/centres-projects-groups/missing-data#dia-missing-data
https://www.lshtm.ac.uk/research/centres-projects-groups/missing-data#dia-missing-data
A dataset containing within group results from an ANCOVA model.
r2rtf_tbl1
r2rtf_tbl1
A data frame with 2 rows and 8 variables.
A dataset containing between group results from an ANCOVA model.
r2rtf_tbl2
r2rtf_tbl2
A data frame with 1 row and 3 variables.
A dataset containing root mean square error from an ANCOVA model.
r2rtf_tbl3
r2rtf_tbl3
A data frame with 1 row and 1 variable.
Add Table Body Attributes to the Table
rtf_body( tbl, col_rel_width = rep(1, ncol(tbl)), as_colheader = TRUE, border_left = "single", border_right = "single", border_top = NULL, border_bottom = NULL, border_first = "single", border_last = "single", border_color_left = NULL, border_color_right = NULL, border_color_top = NULL, border_color_bottom = NULL, border_color_first = NULL, border_color_last = NULL, border_width = 15, cell_height = 0.15, cell_justification = "c", cell_vertical_justification = "top", cell_nrow = NULL, text_font = 1, text_format = NULL, text_font_size = 9, text_color = NULL, text_background_color = NULL, text_justification = NULL, text_indent_first = 0, text_indent_left = 0, text_indent_right = 0, text_space = 1, text_space_before = 15, text_space_after = 15, text_convert = TRUE, group_by = NULL, page_by = NULL, new_page = FALSE, pageby_header = TRUE, pageby_row = "column", subline_by = NULL, last_row = TRUE )
rtf_body( tbl, col_rel_width = rep(1, ncol(tbl)), as_colheader = TRUE, border_left = "single", border_right = "single", border_top = NULL, border_bottom = NULL, border_first = "single", border_last = "single", border_color_left = NULL, border_color_right = NULL, border_color_top = NULL, border_color_bottom = NULL, border_color_first = NULL, border_color_last = NULL, border_width = 15, cell_height = 0.15, cell_justification = "c", cell_vertical_justification = "top", cell_nrow = NULL, text_font = 1, text_format = NULL, text_font_size = 9, text_color = NULL, text_background_color = NULL, text_justification = NULL, text_indent_first = 0, text_indent_left = 0, text_indent_right = 0, text_space = 1, text_space_before = 15, text_space_after = 15, text_convert = TRUE, group_by = NULL, page_by = NULL, new_page = FALSE, pageby_header = TRUE, pageby_row = "column", subline_by = NULL, last_row = TRUE )
tbl |
A data frame. |
col_rel_width |
Column relative width in a vector e.g. c(2,1,1) refers to 2:1:1. Default is NULL for equal column width. |
as_colheader |
A boolean value to indicate whether to add default column header to the table. Default is TRUE to use data frame column names as column header. |
border_left |
Left border type. To vary left border by column, use
character vector with length of vector equal to number of columns displayed
e.g. c("single","single","single"). All possible input can be found in
|
border_right |
Right border type. To vary right border by column, use
character vector with length of vector equal to number of columns displayed
e.g. c("single","single","single"). All possible input can be found in
|
border_top |
Top border type. To vary top border by column, use
character vector with length of vector equal to number of columns displayed
e.g. c("single","single","single"). If it is the first row in a table for this
page, the top border is set to "double" otherwise the border is set to "single".
All possible input can be found in |
border_bottom |
Bottom border type.
To vary bottom border by column, use character vector with length of vector
equal to number of columns displayed e.g. c("single","single","single").
All possible input can be found in |
border_first |
First top border type of the whole table.
All possible input can be found in |
border_last |
Last bottom border type of the whole table.
All possible input can be found in |
border_color_left |
Left border color type. Default is NULL for black. To vary left
border color by column, use character vector with length of vector
equal to number of columns displayed e.g. c("white","red","blue").
All possible input can be found in |
border_color_right |
Right border color type. Default is NULL for black. To vary right
border color by column, use character vector with length of vector
equal to number of columns displayed e.g. c("white","red","blue").
All possible input can be found in |
border_color_top |
Top border color type. Default is NULL for black. To vary top
border color by column, use character vector with length of vector
equal to number of columns displayed e.g. c("white","red","blue").
All possible input can be found in |
border_color_bottom |
Bottom border color type. Default is NULL for black. To vary bottom
border color by column, use character vector with length of vector
equal to number of columns displayed e.g. c("white","red","blue").
All possible input can be found in |
border_color_first |
First top border color type of the whole table. Default is NULL for black.
All possible input can be found in |
border_color_last |
Last bottom border color type of the whole table. Default is NULL for black.
All possible input can be found in |
border_width |
Border width in twips. Default is 15 for 0.0104 inch. |
cell_height |
Cell height in inches. Default is 0.15 for 0.15 inch. |
cell_justification |
Justification type for cell.
All possible input can be found in |
cell_vertical_justification |
Vertical justification type for cell.
All possible input can be found in |
cell_nrow |
Number of rows required in each cell. |
text_font |
Text font type. Default is 1 for Times New Roman. To vary text font type
by column, use numeric vector with length of vector equal to number of
columns displayed e.g. c(1,2,3).All possible input can be found
in |
text_format |
Text format type. Default is NULL for normal. Combination of format type
are permitted as input for e.g. "ub" for bold and underlined text. To vary
text format by column, use character vector with length of vector equal to
number of columns displayed e.g. c("i","u","ib"). All possible input
can be found in |
text_font_size |
Text font size. To vary text font size by column, use numeric vector with length of vector equal to number of columns displayed e.g. c(9,20,40). |
text_color |
Text color type. Default is NULL for black. To vary text color by column,
use character vector with length of vector equal to number of columns
displayed e.g. c("white","red","blue"). All possible input can be found
in |
text_background_color |
Text background color type. Default is NULL for white. To vary
text color by column, use character vector with length of vector
equal to number of columns displayed e.g. c("white","red","blue").
All possible input can be found in |
text_justification |
Justification type for text. Default is "c" for center justification.
To vary text justification by column, use character vector with
length of vector equal to number of columns displayed e.g. c("c","l","r").
All possible input can be found in |
text_indent_first |
A value of text indent in first line. The unit is twip. |
text_indent_left |
A value of text left indent. The unit is twip. |
text_indent_right |
A value of text right indent. The unit is twip. |
text_space |
Line space between paragraph in twips. Default is 0. |
text_space_before |
Line space before a paragraph in twips. |
text_space_after |
Line space after a paragraph in twips. |
text_convert |
A logical value to convert special characters. |
group_by |
A character vector of variable names in |
page_by |
Column names in a character vector to group by table in sections. |
new_page |
A boolean value to indicate whether to separate grouped table into pages by sections. Default is FALSE. |
pageby_header |
A boolean value to display |
pageby_row |
A character vector of location of page_by variable. Possible input are 'column' or 'first_row'. |
subline_by |
Column names in a character vector to subline by table in sections. |
last_row |
A boolean value to indicate whether the table contains the last row of the final table. |
the same data frame tbl
with additional attributes for table body
The contents of this section are shown in PDF user manual only.
library(dplyr) # required to run examples data(r2rtf_tbl1) r2rtf_tbl1 %>% rtf_body( col_rel_width = c(3, 1, 3, 1, 3, 1, 3, 5), text_justification = c("l", rep("c", 7)), last_row = FALSE ) %>% attributes()
library(dplyr) # required to run examples data(r2rtf_tbl1) r2rtf_tbl1 %>% rtf_body( col_rel_width = c(3, 1, 3, 1, 3, 1, 3, 5), text_justification = c("l", rep("c", 7)), last_row = FALSE ) %>% attributes()
Add Column Header Attributes to Table
rtf_colheader( tbl, colheader = NULL, col_rel_width = NULL, border_left = "single", border_right = "single", border_top = "single", border_bottom = "", border_color_left = NULL, border_color_right = NULL, border_color_top = NULL, border_color_bottom = NULL, border_width = 15, cell_height = 0.15, cell_justification = "c", cell_vertical_justification = "bottom", cell_nrow = NULL, text_font = 1, text_format = NULL, text_font_size = 9, text_color = NULL, text_background_color = NULL, text_justification = "c", text_indent_first = 0, text_indent_left = 0, text_indent_right = 0, text_space = 1, text_space_before = 15, text_space_after = 15, text_convert = TRUE )
rtf_colheader( tbl, colheader = NULL, col_rel_width = NULL, border_left = "single", border_right = "single", border_top = "single", border_bottom = "", border_color_left = NULL, border_color_right = NULL, border_color_top = NULL, border_color_bottom = NULL, border_width = 15, cell_height = 0.15, cell_justification = "c", cell_vertical_justification = "bottom", cell_nrow = NULL, text_font = 1, text_format = NULL, text_font_size = 9, text_color = NULL, text_background_color = NULL, text_justification = "c", text_indent_first = 0, text_indent_left = 0, text_indent_right = 0, text_space = 1, text_space_before = 15, text_space_after = 15, text_convert = TRUE )
tbl |
A data frame. |
colheader |
A character string that uses " | " to separate column names. Default is NULL for a blank column header. |
col_rel_width |
A Column relative width in a vector e.g. c(2,1,1) refers to 2:1:1. Default is NULL for equal column width. |
border_left |
Left border type. To vary left border by column, use
character vector with length of vector equal to number of columns displayed
e.g. c("single","single","single"). All possible input can be found in
|
border_right |
Right border type. To vary right border by column, use
character vector with length of vector equal to number of columns displayed
e.g. c("single","single","single"). All possible input can be found in
|
border_top |
Top border type. To vary top border by column, use
character vector with length of vector equal to number of columns displayed
e.g. c("single","single","single"). If it is the first row in a table for this
page, the top border is set to "double" otherwise the border is set to "single".
All possible input can be found in |
border_bottom |
Bottom border type.
To vary bottom border by column, use character vector with length of vector
equal to number of columns displayed e.g. c("single","single","single").
All possible input can be found in |
border_color_left |
Left border color type. Default is NULL for black. To vary left
border color by column, use character vector with length of vector
equal to number of columns displayed e.g. c("white","red","blue").
All possible input can be found in |
border_color_right |
Right border color type. Default is NULL for black. To vary right
border color by column, use character vector with length of vector
equal to number of columns displayed e.g. c("white","red","blue").
All possible input can be found in |
border_color_top |
Top border color type. Default is NULL for black. To vary top
border color by column, use character vector with length of vector
equal to number of columns displayed e.g. c("white","red","blue").
All possible input can be found in |
border_color_bottom |
Bottom border color type. Default is NULL for black. To vary bottom
border color by column, use character vector with length of vector
equal to number of columns displayed e.g. c("white","red","blue").
All possible input can be found in |
border_width |
Border width in twips. Default is 15 for 0.0104 inch. |
cell_height |
Cell height in inches. Default is 0.15 for 0.15 inch. |
cell_justification |
Justification type for cell.
All possible input can be found in |
cell_vertical_justification |
Vertical justification type for cell.
All possible input can be found in |
cell_nrow |
Number of rows required in each cell. |
text_font |
Text font type. Default is 1 for Times New Roman. To vary text font type
by column, use numeric vector with length of vector equal to number of
columns displayed e.g. c(1,2,3).All possible input can be found
in |
text_format |
Text format type. Default is NULL for normal. Combination of format type
are permitted as input for e.g. "ub" for bold and underlined text. To vary
text format by column, use character vector with length of vector equal to
number of columns displayed e.g. c("i","u","ib"). All possible input
can be found in |
text_font_size |
Text font size. To vary text font size by column, use numeric vector with length of vector equal to number of columns displayed e.g. c(9,20,40). |
text_color |
Text color type. Default is NULL for black. To vary text color by column,
use character vector with length of vector equal to number of columns
displayed e.g. c("white","red","blue"). All possible input can be found
in |
text_background_color |
Text background color type. Default is NULL for white. To vary
text color by column, use character vector with length of vector
equal to number of columns displayed e.g. c("white","red","blue").
All possible input can be found in |
text_justification |
Justification type for text. Default is "c" for center justification.
To vary text justification by column, use character vector with
length of vector equal to number of columns displayed e.g. c("c","l","r").
All possible input can be found in |
text_indent_first |
A value of text indent in first line. The unit is twip. |
text_indent_left |
A value of text left indent. The unit is twip. |
text_indent_right |
A value of text right indent. The unit is twip. |
text_space |
Line space between paragraph in twips. Default is 0. |
text_space_before |
Line space before a paragraph in twips. |
text_space_after |
Line space after a paragraph in twips. |
text_convert |
A logical value to convert special characters. |
The same data frame tbl
with additional attributes for table column header.
The contents of this section are shown in PDF user manual only.
library(dplyr) # required to run examples data(r2rtf_tbl1) r2rtf_tbl1 %>% rtf_colheader( colheader = "Treatment | N | Mean (SD) | N | Mean (SD) | N | Mean (SD) | LS Mean (95% CI)\\dagger", text_format = c("b", "", "u", "", "u", "", "u", "i") ) %>% attr("rtf_colheader")
library(dplyr) # required to run examples data(r2rtf_tbl1) r2rtf_tbl1 %>% rtf_colheader( colheader = "Treatment | N | Mean (SD) | N | Mean (SD) | N | Mean (SD) | LS Mean (95% CI)\\dagger", text_format = c("b", "", "u", "", "u", "", "u", "i") ) %>% attr("rtf_colheader")
This function extracts table/figure attributes and render to RTF encoding that is ready to save to an RTF file.
rtf_encode( tbl, doc_type = "table", page_title = "all", page_footnote = "last", page_source = "last", verbose = FALSE )
rtf_encode( tbl, doc_type = "table", page_title = "all", page_footnote = "last", page_source = "last", verbose = FALSE )
tbl |
A data frame for table or a list of binary string for figure. |
doc_type |
The doc_type of input, default is table. |
page_title |
A character of title displaying location. Possible values are "first", "last" and "all". |
page_footnote |
A character of title displaying location. Possible values are "first", "last" and "all". |
page_source |
A character of title displaying location. Possible values are "first", "last" and "all". |
verbose |
a boolean value to return more details of RTF encoding. |
For \code{rtf_encode}, a vector of RTF code. For \code{write_rtf}, no return value.
The contents of this section are shown in PDF user manual only.
library(dplyr) # required to run examples # Example 1 head(iris) %>% rtf_body() %>% rtf_encode() %>% write_rtf(file = file.path(tempdir(), "table1.rtf")) # Example 2 ## Not run: library(dplyr) # required to run examples file <- file.path(tempdir(), "figure1.png") png(file) plot(1:10) dev.off() # Read in PNG file in binary format rtf_read_figure(file) %>% rtf_figure() %>% rtf_encode(doc_type = "figure") %>% write_rtf(file = file.path(tempdir(), "figure1.rtf")) ## End(Not run) # Example 3 ## convert tbl_1 to the table body. Add title, subtitle, two table ## headers, and footnotes to the table body. data(r2rtf_tbl2) ## convert r2rtf_tbl2 to the table body. Add a table column header to table body. t2 <- r2rtf_tbl2 %>% rtf_colheader( colheader = "Pairwise Comparison | Difference in LS Mean(95% CI)\\dagger | p-Value", text_justification = c("l", "c", "c") ) %>% rtf_body( col_rel_width = c(8, 7, 5), text_justification = c("l", "c", "c"), last_row = FALSE ) # concatenate a list of table and save to an RTF file t2 %>% rtf_encode() %>% write_rtf(file.path(tempdir(), "table2.rtf"))
library(dplyr) # required to run examples # Example 1 head(iris) %>% rtf_body() %>% rtf_encode() %>% write_rtf(file = file.path(tempdir(), "table1.rtf")) # Example 2 ## Not run: library(dplyr) # required to run examples file <- file.path(tempdir(), "figure1.png") png(file) plot(1:10) dev.off() # Read in PNG file in binary format rtf_read_figure(file) %>% rtf_figure() %>% rtf_encode(doc_type = "figure") %>% write_rtf(file = file.path(tempdir(), "figure1.rtf")) ## End(Not run) # Example 3 ## convert tbl_1 to the table body. Add title, subtitle, two table ## headers, and footnotes to the table body. data(r2rtf_tbl2) ## convert r2rtf_tbl2 to the table body. Add a table column header to table body. t2 <- r2rtf_tbl2 %>% rtf_colheader( colheader = "Pairwise Comparison | Difference in LS Mean(95% CI)\\dagger | p-Value", text_justification = c("l", "c", "c") ) %>% rtf_body( col_rel_width = c(8, 7, 5), text_justification = c("l", "c", "c"), last_row = FALSE ) # concatenate a list of table and save to an RTF file t2 %>% rtf_encode() %>% write_rtf(file.path(tempdir(), "table2.rtf"))
Add Figure Attributes
rtf_figure(tbl, fig_width = 5, fig_height = 5, fig_format = NULL)
rtf_figure(tbl, fig_width = 5, fig_height = 5, fig_format = NULL)
tbl |
A data frame. |
fig_width |
the width of figures in inch |
fig_height |
the height of figures in inch |
fig_format |
the figure format defined in |
the same data frame tbl
with additional attributes for figure body
The contents of this section are shown in PDF user manual only.
## Not run: library(dplyr) # required to run examples file <- file.path(tempdir(), "figure1.png") png(file) plot(1:10) dev.off() # Read in PNG file in binary format rtf_read_figure(file) %>% rtf_figure() %>% attributes() ## End(Not run)
## Not run: library(dplyr) # required to run examples file <- file.path(tempdir(), "figure1.png") png(file) plot(1:10) dev.off() # Read in PNG file in binary format rtf_read_figure(file) %>% rtf_figure() %>% attributes() ## End(Not run)
Add Footnote Attributes to Table
rtf_footnote( tbl, footnote = "", border_left = "single", border_right = "single", border_top = "", border_bottom = "single", border_color_left = NULL, border_color_right = NULL, border_color_top = NULL, border_color_bottom = NULL, border_width = 15, cell_height = 0.15, cell_justification = "c", cell_vertical_justification = "top", cell_nrow = NULL, text_font = 1, text_format = NULL, text_font_size = 9, text_color = NULL, text_background_color = NULL, text_justification = "l", text_indent_first = 0, text_indent_left = 0, text_indent_right = 0, text_indent_reference = "table", text_space = 1, text_space_before = 15, text_space_after = 15, text_convert = TRUE, as_table = TRUE )
rtf_footnote( tbl, footnote = "", border_left = "single", border_right = "single", border_top = "", border_bottom = "single", border_color_left = NULL, border_color_right = NULL, border_color_top = NULL, border_color_bottom = NULL, border_width = 15, cell_height = 0.15, cell_justification = "c", cell_vertical_justification = "top", cell_nrow = NULL, text_font = 1, text_format = NULL, text_font_size = 9, text_color = NULL, text_background_color = NULL, text_justification = "l", text_indent_first = 0, text_indent_left = 0, text_indent_right = 0, text_indent_reference = "table", text_space = 1, text_space_before = 15, text_space_after = 15, text_convert = TRUE, as_table = TRUE )
tbl |
A data frame. |
footnote |
A vector of character for footnote text. |
border_left |
Left border type. To vary left border by column, use
character vector with length of vector equal to number of columns displayed
e.g. c("single","single","single"). All possible input can be found in
|
border_right |
Right border type. To vary right border by column, use
character vector with length of vector equal to number of columns displayed
e.g. c("single","single","single"). All possible input can be found in
|
border_top |
Top border type. To vary top border by column, use
character vector with length of vector equal to number of columns displayed
e.g. c("single","single","single"). If it is the first row in a table for this
page, the top border is set to "double" otherwise the border is set to "single".
All possible input can be found in |
border_bottom |
Bottom border type.
To vary bottom border by column, use character vector with length of vector
equal to number of columns displayed e.g. c("single","single","single").
All possible input can be found in |
border_color_left |
Left border color type. Default is NULL for black. To vary left
border color by column, use character vector with length of vector
equal to number of columns displayed e.g. c("white","red","blue").
All possible input can be found in |
border_color_right |
Right border color type. Default is NULL for black. To vary right
border color by column, use character vector with length of vector
equal to number of columns displayed e.g. c("white","red","blue").
All possible input can be found in |
border_color_top |
Top border color type. Default is NULL for black. To vary top
border color by column, use character vector with length of vector
equal to number of columns displayed e.g. c("white","red","blue").
All possible input can be found in |
border_color_bottom |
Bottom border color type. Default is NULL for black. To vary bottom
border color by column, use character vector with length of vector
equal to number of columns displayed e.g. c("white","red","blue").
All possible input can be found in |
border_width |
Border width in twips. Default is 15 for 0.0104 inch. |
cell_height |
Cell height in inches. Default is 0.15 for 0.15 inch. |
cell_justification |
Justification type for cell.
All possible input can be found in |
cell_vertical_justification |
Vertical justification type for cell.
All possible input can be found in |
cell_nrow |
Number of rows required in each cell. |
text_font |
Text font type. Default is 1 for Times New Roman. To vary text font type
by column, use numeric vector with length of vector equal to number of
columns displayed e.g. c(1,2,3).All possible input can be found
in |
text_format |
Text format type. Default is NULL for normal. Combination of format type
are permitted as input for e.g. "ub" for bold and underlined text. To vary
text format by column, use character vector with length of vector equal to
number of columns displayed e.g. c("i","u","ib"). All possible input
can be found in |
text_font_size |
Text font size. To vary text font size by column, use numeric vector with length of vector equal to number of columns displayed e.g. c(9,20,40). |
text_color |
Text color type. Default is NULL for black. To vary text color by column,
use character vector with length of vector equal to number of columns
displayed e.g. c("white","red","blue"). All possible input can be found
in |
text_background_color |
Text background color type. Default is NULL for white. To vary
text color by column, use character vector with length of vector
equal to number of columns displayed e.g. c("white","red","blue").
All possible input can be found in |
text_justification |
Justification type for text. Default is "c" for center justification.
To vary text justification by column, use character vector with
length of vector equal to number of columns displayed e.g. c("c","l","r").
All possible input can be found in |
text_indent_first |
A value of text indent in first line. The unit is twip. |
text_indent_left |
A value of text left indent. The unit is twip. |
text_indent_right |
A value of text right indent. The unit is twip. |
text_indent_reference |
The reference start point of text indent. Accept |
text_space |
Line space between paragraph in twips. Default is 0. |
text_space_before |
Line space before a paragraph in twips. |
text_space_after |
Line space after a paragraph in twips. |
text_convert |
A logical value to convert special characters. |
as_table |
A logical value to display it as a table. |
the same data frame tbl
with additional attributes for table footnote
The contents of this section are shown in PDF user manual only.
library(dplyr) # required to run examples data(r2rtf_tbl1) r2rtf_tbl1 %>% rtf_footnote("\\dagger Based on an ANCOVA model.") %>% attr("rtf_footnote")
library(dplyr) # required to run examples data(r2rtf_tbl1) r2rtf_tbl1 %>% rtf_footnote("\\dagger Based on an ANCOVA model.") %>% attr("rtf_footnote")
Add RTF File Page Information
rtf_page( tbl, orientation = "portrait", width = ifelse(orientation == "portrait", 8.5, 11), height = ifelse(orientation == "portrait", 11, 8.5), margin = set_margin("wma", orientation), nrow = ifelse(orientation == "portrait", 40, 24), border_first = "double", border_last = "double", border_color_first = NULL, border_color_last = NULL, col_width = width - ifelse(orientation == "portrait", 2.25, 2.5), use_color = FALSE )
rtf_page( tbl, orientation = "portrait", width = ifelse(orientation == "portrait", 8.5, 11), height = ifelse(orientation == "portrait", 11, 8.5), margin = set_margin("wma", orientation), nrow = ifelse(orientation == "portrait", 40, 24), border_first = "double", border_last = "double", border_color_first = NULL, border_color_last = NULL, col_width = width - ifelse(orientation == "portrait", 2.25, 2.5), use_color = FALSE )
tbl |
A data frame. |
orientation |
Orientation in 'portrait' or 'landscape'. |
width |
A numeric value of page width in inches. |
height |
A numeric value of page width in inches. |
margin |
A numeric vector of length 6 for page margin. The value set left, right, top, bottom, header and footer
margin in order. Default value depends on the page orientation and set by |
nrow |
Number of rows in each page. |
border_first |
First top border type of the whole table.
All possible input can be found in |
border_last |
Last bottom border type of the whole table.
All possible input can be found in |
border_color_first |
First top border color type of the whole table. Default is NULL for black.
All possible input can be found in |
border_color_last |
Last bottom border color type of the whole table. Default is NULL for black.
All possible input can be found in |
col_width |
A numeric value of total column width in inch. Default is |
use_color |
A logical value to use color in the output. |
the same data frame tbl
with additional attributes for page features
The contents of this section are shown in PDF user manual only.
library(dplyr) # required to run examples data(r2rtf_tbl1) r2rtf_tbl1 %>% rtf_page() %>% attr("page")
library(dplyr) # required to run examples data(r2rtf_tbl1) r2rtf_tbl1 %>% rtf_page() %>% attr("page")
Add RTF Page Header Information
rtf_page_header( tbl, text = "Page \\pagenumber of \\pagefield", text_font = 1, text_format = NULL, text_font_size = 12, text_color = NULL, text_background_color = NULL, text_justification = "r", text_indent_first = 0, text_indent_left = 0, text_indent_right = 0, text_space = 1, text_space_before = 15, text_space_after = 15, text_convert = TRUE )
rtf_page_header( tbl, text = "Page \\pagenumber of \\pagefield", text_font = 1, text_format = NULL, text_font_size = 12, text_color = NULL, text_background_color = NULL, text_justification = "r", text_indent_first = 0, text_indent_left = 0, text_indent_right = 0, text_space = 1, text_space_before = 15, text_space_after = 15, text_convert = TRUE )
tbl |
A data frame. |
text |
A character string. |
text_font |
Text font type. Default is 1 for Times New Roman. To vary text font type
by column, use numeric vector with length of vector equal to number of
columns displayed e.g. c(1,2,3).All possible input can be found
in |
text_format |
Text format type. Default is NULL for normal. Combination of format type
are permitted as input for e.g. "ub" for bold and underlined text. To vary
text format by column, use character vector with length of vector equal to
number of columns displayed e.g. c("i","u","ib"). All possible input
can be found in |
text_font_size |
Text font size. To vary text font size by column, use numeric vector with length of vector equal to number of columns displayed e.g. c(9,20,40). |
text_color |
Text color type. Default is NULL for black. To vary text color by column,
use character vector with length of vector equal to number of columns
displayed e.g. c("white","red","blue"). All possible input can be found
in |
text_background_color |
Text background color type. Default is NULL for white. To vary
text color by column, use character vector with length of vector
equal to number of columns displayed e.g. c("white","red","blue").
All possible input can be found in |
text_justification |
Justification type for text. Default is "c" for center justification.
To vary text justification by column, use character vector with
length of vector equal to number of columns displayed e.g. c("c","l","r").
All possible input can be found in |
text_indent_first |
A value of text indent in first line. The unit is twip. |
text_indent_left |
A value of text left indent. The unit is twip. |
text_indent_right |
A value of text right indent. The unit is twip. |
text_space |
Line space between paragraph in twips. Default is 0. |
text_space_before |
Line space before a paragraph in twips. |
text_space_after |
Line space after a paragraph in twips. |
text_convert |
A logical value to convert special characters. |
Supported format is listed in r2rtf:::fig_format()
.
rtf_read_figure(file)
rtf_read_figure(file)
file |
A character vector of figure file paths. |
a list of binary data vector returned by readBin
The contents of this section are shown in PDF user manual only.
## Not run: # Read in PNG file in binary format file <- tempfile("figure", fileext = ".png") png(file) plot(1:10) dev.off() rtf_read_figure(file) # Read in EMF file in binary format library(devEMF) file <- tempfile("figure", fileext = ".emf") emf(file) plot(1:10) dev.off() rtf_read_figure(file) ## End(Not run)
## Not run: # Read in PNG file in binary format file <- tempfile("figure", fileext = ".png") png(file) plot(1:10) dev.off() rtf_read_figure(file) # Read in EMF file in binary format library(devEMF) file <- tempfile("figure", fileext = ".emf") emf(file) plot(1:10) dev.off() rtf_read_figure(file) ## End(Not run)
Read PNG Figures into Binary Files
rtf_read_png(file)
rtf_read_png(file)
file |
A character vector of PNG file paths. |
a list of binary data vector returned by readBin
The contents of this section are shown in PDF user manual only.
Text to Formatted RTF Encode
rtf_rich_text( text, theme = list(.emph = list(format = "i"), .strong = list(format = "b")) )
rtf_rich_text( text, theme = list(.emph = list(format = "i"), .strong = list(format = "b")) )
text |
Plain text. |
theme |
Named list defining themes for tags. See |
The contents of this section are shown in PDF user manual only.
rtf_rich_text( text = paste( "This is {.emph important}.", "This is {.strong relevant}.", "This is {.zebra ZEBRA}." ), theme = list( .emph = list(format = "i"), .strong = list(format = "b"), .zebra = list(color = "white", background_color = "black") ) )
rtf_rich_text( text = paste( "This is {.emph important}.", "This is {.strong relevant}.", "This is {.zebra ZEBRA}." ), theme = list( .emph = list(format = "i"), .strong = list(format = "b"), .zebra = list(color = "white", background_color = "black") ) )
Add Data Source Attributes to the Table
rtf_source( tbl, source = "", border_left = "single", border_right = "single", border_top = "", border_bottom = "single", border_color_left = NULL, border_color_right = NULL, border_color_top = NULL, border_color_bottom = NULL, border_width = 15, cell_height = 0.15, cell_justification = "c", cell_vertical_justification = "top", cell_nrow = NULL, text_font = 1, text_format = NULL, text_font_size = 9, text_color = NULL, text_background_color = NULL, text_justification = "c", text_indent_first = 0, text_indent_left = 0, text_indent_right = 0, text_indent_reference = "table", text_space = 1, text_space_before = 15, text_space_after = 15, text_convert = TRUE, as_table = FALSE )
rtf_source( tbl, source = "", border_left = "single", border_right = "single", border_top = "", border_bottom = "single", border_color_left = NULL, border_color_right = NULL, border_color_top = NULL, border_color_bottom = NULL, border_width = 15, cell_height = 0.15, cell_justification = "c", cell_vertical_justification = "top", cell_nrow = NULL, text_font = 1, text_format = NULL, text_font_size = 9, text_color = NULL, text_background_color = NULL, text_justification = "c", text_indent_first = 0, text_indent_left = 0, text_indent_right = 0, text_indent_reference = "table", text_space = 1, text_space_before = 15, text_space_after = 15, text_convert = TRUE, as_table = FALSE )
tbl |
A data frame. |
source |
A character string. |
border_left |
Left border type. To vary left border by column, use
character vector with length of vector equal to number of columns displayed
e.g. c("single","single","single"). All possible input can be found in
|
border_right |
Right border type. To vary right border by column, use
character vector with length of vector equal to number of columns displayed
e.g. c("single","single","single"). All possible input can be found in
|
border_top |
Top border type. To vary top border by column, use
character vector with length of vector equal to number of columns displayed
e.g. c("single","single","single"). If it is the first row in a table for this
page, the top border is set to "double" otherwise the border is set to "single".
All possible input can be found in |
border_bottom |
Bottom border type.
To vary bottom border by column, use character vector with length of vector
equal to number of columns displayed e.g. c("single","single","single").
All possible input can be found in |
border_color_left |
Left border color type. Default is NULL for black. To vary left
border color by column, use character vector with length of vector
equal to number of columns displayed e.g. c("white","red","blue").
All possible input can be found in |
border_color_right |
Right border color type. Default is NULL for black. To vary right
border color by column, use character vector with length of vector
equal to number of columns displayed e.g. c("white","red","blue").
All possible input can be found in |
border_color_top |
Top border color type. Default is NULL for black. To vary top
border color by column, use character vector with length of vector
equal to number of columns displayed e.g. c("white","red","blue").
All possible input can be found in |
border_color_bottom |
Bottom border color type. Default is NULL for black. To vary bottom
border color by column, use character vector with length of vector
equal to number of columns displayed e.g. c("white","red","blue").
All possible input can be found in |
border_width |
Border width in twips. Default is 15 for 0.0104 inch. |
cell_height |
Cell height in inches. Default is 0.15 for 0.15 inch. |
cell_justification |
Justification type for cell.
All possible input can be found in |
cell_vertical_justification |
Vertical justification type for cell.
All possible input can be found in |
cell_nrow |
Number of rows required in each cell. |
text_font |
Text font type. Default is 1 for Times New Roman. To vary text font type
by column, use numeric vector with length of vector equal to number of
columns displayed e.g. c(1,2,3).All possible input can be found
in |
text_format |
Text format type. Default is NULL for normal. Combination of format type
are permitted as input for e.g. "ub" for bold and underlined text. To vary
text format by column, use character vector with length of vector equal to
number of columns displayed e.g. c("i","u","ib"). All possible input
can be found in |
text_font_size |
Text font size. To vary text font size by column, use numeric vector with length of vector equal to number of columns displayed e.g. c(9,20,40). |
text_color |
Text color type. Default is NULL for black. To vary text color by column,
use character vector with length of vector equal to number of columns
displayed e.g. c("white","red","blue"). All possible input can be found
in |
text_background_color |
Text background color type. Default is NULL for white. To vary
text color by column, use character vector with length of vector
equal to number of columns displayed e.g. c("white","red","blue").
All possible input can be found in |
text_justification |
Justification type for text. Default is "c" for center justification.
To vary text justification by column, use character vector with
length of vector equal to number of columns displayed e.g. c("c","l","r").
All possible input can be found in |
text_indent_first |
A value of text indent in first line. The unit is twip. |
text_indent_left |
A value of text left indent. The unit is twip. |
text_indent_right |
A value of text right indent. The unit is twip. |
text_indent_reference |
The reference start point of text indent. Accept |
text_space |
Line space between paragraph in twips. Default is 0. |
text_space_before |
Line space before a paragraph in twips. |
text_space_after |
Line space after a paragraph in twips. |
text_convert |
A logical value to convert special characters. |
as_table |
A logical value to display it as a table. |
the same data frame tbl
with additional attributes for data source of a table
The contents of this section are shown in PDF user manual only.
library(dplyr) # required to run examples data(r2rtf_tbl1) r2rtf_tbl1 %>% rtf_source("Source: [study999:adam-adeff]") %>% attr("rtf_source")
library(dplyr) # required to run examples data(r2rtf_tbl1) r2rtf_tbl1 %>% rtf_source("Source: [study999:adam-adeff]") %>% attr("rtf_source")
Add subline attributes to the object
rtf_subline( tbl, text, text_font = 1, text_format = NULL, text_font_size = 12, text_color = NULL, text_background_color = NULL, text_justification = "l", text_indent_first = 0, text_indent_left = 0, text_indent_right = 0, text_indent_reference = "table", text_space = 1, text_space_before = 180, text_space_after = 180, text_convert = TRUE )
rtf_subline( tbl, text, text_font = 1, text_format = NULL, text_font_size = 12, text_color = NULL, text_background_color = NULL, text_justification = "l", text_indent_first = 0, text_indent_left = 0, text_indent_right = 0, text_indent_reference = "table", text_space = 1, text_space_before = 180, text_space_after = 180, text_convert = TRUE )
tbl |
A data frame. |
text |
A character vector of subline |
text_font |
Text font type. Default is 1 for Times New Roman. To vary text font type
by column, use numeric vector with length of vector equal to number of
columns displayed e.g. c(1,2,3).All possible input can be found
in |
text_format |
Text format type. Default is NULL for normal. Combination of format type
are permitted as input for e.g. "ub" for bold and underlined text. To vary
text format by column, use character vector with length of vector equal to
number of columns displayed e.g. c("i","u","ib"). All possible input
can be found in |
text_font_size |
Text font size. To vary text font size by column, use numeric vector with length of vector equal to number of columns displayed e.g. c(9,20,40). |
text_color |
Text color type. Default is NULL for black. To vary text color by column,
use character vector with length of vector equal to number of columns
displayed e.g. c("white","red","blue"). All possible input can be found
in |
text_background_color |
Text background color type. Default is NULL for white. To vary
text color by column, use character vector with length of vector
equal to number of columns displayed e.g. c("white","red","blue").
All possible input can be found in |
text_justification |
Justification type for text. Default is "c" for center justification.
To vary text justification by column, use character vector with
length of vector equal to number of columns displayed e.g. c("c","l","r").
All possible input can be found in |
text_indent_first |
A value of text indent in first line. The unit is twip. |
text_indent_left |
A value of text left indent. The unit is twip. |
text_indent_right |
A value of text right indent. The unit is twip. |
text_indent_reference |
The reference start point of text indent. Accept |
text_space |
Line space between paragraph in twips. Default is 0. |
text_space_before |
Line space before a paragraph in twips. |
text_space_after |
Line space after a paragraph in twips. |
text_convert |
A logical value to convert special characters. |
the same data frame tbl
with additional attributes for table title
The contents of this section are shown in PDF user manual only.
Add title, subtitle, and other attributes to the object
rtf_title( tbl, title = NULL, subtitle = NULL, text_font = 1, text_format = NULL, text_font_size = 12, text_color = NULL, text_background_color = NULL, text_justification = "c", text_indent_first = 0, text_indent_left = 0, text_indent_right = 0, text_indent_reference = "table", text_space = 1, text_space_before = 180, text_space_after = 180, text_convert = TRUE )
rtf_title( tbl, title = NULL, subtitle = NULL, text_font = 1, text_format = NULL, text_font_size = 12, text_color = NULL, text_background_color = NULL, text_justification = "c", text_indent_first = 0, text_indent_left = 0, text_indent_right = 0, text_indent_reference = "table", text_space = 1, text_space_before = 180, text_space_after = 180, text_convert = TRUE )
tbl |
A data frame. |
title |
Title in a character string. |
subtitle |
Subtitle in a character string. |
text_font |
Text font type. Default is 1 for Times New Roman. To vary text font type
by column, use numeric vector with length of vector equal to number of
columns displayed e.g. c(1,2,3).All possible input can be found
in |
text_format |
Text format type. Default is NULL for normal. Combination of format type
are permitted as input for e.g. "ub" for bold and underlined text. To vary
text format by column, use character vector with length of vector equal to
number of columns displayed e.g. c("i","u","ib"). All possible input
can be found in |
text_font_size |
Text font size. To vary text font size by column, use numeric vector with length of vector equal to number of columns displayed e.g. c(9,20,40). |
text_color |
Text color type. Default is NULL for black. To vary text color by column,
use character vector with length of vector equal to number of columns
displayed e.g. c("white","red","blue"). All possible input can be found
in |
text_background_color |
Text background color type. Default is NULL for white. To vary
text color by column, use character vector with length of vector
equal to number of columns displayed e.g. c("white","red","blue").
All possible input can be found in |
text_justification |
Justification type for text. Default is "c" for center justification.
To vary text justification by column, use character vector with
length of vector equal to number of columns displayed e.g. c("c","l","r").
All possible input can be found in |
text_indent_first |
A value of text indent in first line. The unit is twip. |
text_indent_left |
A value of text left indent. The unit is twip. |
text_indent_right |
A value of text right indent. The unit is twip. |
text_indent_reference |
The reference start point of text indent. Accept |
text_space |
Line space between paragraph in twips. Default is 0. |
text_space_before |
Line space before a paragraph in twips. |
text_space_after |
Line space after a paragraph in twips. |
text_convert |
A logical value to convert special characters. |
the same data frame tbl
with additional attributes for table title
The contents of this section are shown in PDF user manual only.
library(dplyr) # required to run examples data(r2rtf_tbl1) r2rtf_tbl1 %>% rtf_title(title = "ANCOVA of Change from Baseline at Week 8") %>% attr("rtf_title")
library(dplyr) # required to run examples data(r2rtf_tbl1) r2rtf_tbl1 %>% rtf_title(title = "ANCOVA of Change from Baseline at Week 8") %>% attr("rtf_title")
Convert a UTF-8 Encoded Character String to a RTF Encoded String
utf8Tortf(text)
utf8Tortf(text)
text |
A string to be converted. If the unicode of a character is less than 128 (including all character on a keyboard), the character is as is. If the unicode of a character is larger or equal to 128, the character will be encoded. |
The contents of this section are shown in PDF user manual only.
Burke, S. M. (2003). RTF Pocket Guide. " O'Reilly Media, Inc.".
The write_rtf function writes rtf encoding string to an .rtf file
write_rtf(rtf, file)
write_rtf(rtf, file)
rtf |
A character rtf encoding string rendered by |
file |
A character string naming a file to save rtf file. |
The contents of this section are shown in PDF user manual only.