You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
It’s a bit lengthy and tricky to add the format attributes into the dataframe following the paradigm of r2rtf, especially for the complicated table outputs with multiple levels of header or different format for specific rows or columns.
Describe the solution you'd like
We could have a folder/object to contain the format setting for each kinds of tables. When we generate the output, we could use the do.call() to assign the attributes into the dataframe based on the format settings in the gallery. Below is an example to assign the attributes of header into the dataframe.
## List of raw header informationcolheader_list<-list(
list(
header= c("", "col1",
"col2",
"col3",
"col4"),
match_col_width= c(1, 2, 2, 3, 3, 4, 4, 5, 5),
style='b'),
list(
header= c("", rep(c("n", "(%)"), 4)),
match_col_width= c(1:9),
no_border_left= c(3, 5, 7, 9),
no_border_top= c(1),
style='b')
)
## Convert the meta information of header to be fit in the r2rtfheader_format<- utils_rtf_header_format(
colheader_list=colheader_list,
column_width=column_width[-length(column_width)]
)
## Function to assign all headers' attributes into the dataframeutils_rtf_header_combiner<-function(tbl,
header_format=header_format) {
pipe_header<-1:length(header_format)
names(pipe_header) <- paste0('h', pipe_header)
## Define the function for each pipe. ----header_exec<-function(header,
text_format,
text_justification,
col_rel_width,
border_left,
border_top,
text_font_size) {
tbl|>r2rtf::rtf_colheader(
colheader=header,
text_format=text_format,
col_rel_width=col_rel_width,
text_justification=text_justification,
border_left=border_left,
border_top=border_top,
text_font_size=text_font_size
)
}
## Assign header execution function to every element of header pipeline.for (iin1:length(header_format)) {
assign(paste0('h', i), header_exec, envir= environment())
}
## With do.call function to assign the header format to inputdata.for (funcin names(pipe_header[order(pipe_header)]))
{
tbl<- do.call(func, header_format[[func]])
}
tbl<- structure(tbl, class= c(class(tbl))) ## preserve the object attributes
}
## Load the data
load(file.path(tmppath, 'test.Rdata'))
## Assign the attributes dynamicallytbl<- utils_rtf_header_combiner(tbl=test,
header_format=header_format)
Describe alternatives you've considered
Further down the line, we could have a formatting gallery for all outputs. So when we generate a specific output, we can directly extract the format setting from gallery and assign it to the outputs.
So I'd like to know if the developers and maintainers are interested in this topic, then we can contribute to this package to add a vignette or some helper functions into the r2rtf package. Thanks.
The text was updated successfully, but these errors were encountered:
I agree, starting from a best practice vignette to offer recipes on automating large-scale production of tables sounds like a good plan without making it too org-specific or a huge commitment. If the recipes happen to come with some reusable functions that would save a lot of typing and boilerplate code, we can incorporate them into the package.
As an example, gt has some API to work with a collection of gt tables although we don't have to model after it.
Thanks for your suggestions @nanxstats, @elong0527, I agree with Nan that a recipes vignette would be good starting point. I will just fork the repo and then make the pull request.
Is your feature request related to a problem? Please describe.
It’s a bit lengthy and tricky to add the format attributes into the dataframe following the paradigm of r2rtf, especially for the complicated table outputs with multiple levels of header or different format for specific rows or columns.
Describe the solution you'd like
We could have a folder/object to contain the format setting for each kinds of tables. When we generate the output, we could use the do.call() to assign the attributes into the dataframe based on the format settings in the gallery. Below is an example to assign the attributes of header into the dataframe.
Describe alternatives you've considered
Further down the line, we could have a formatting gallery for all outputs. So when we generate a specific output, we can directly extract the format setting from gallery and assign it to the outputs.
So I'd like to know if the developers and maintainers are interested in this topic, then we can contribute to this package to add a vignette or some helper functions into the r2rtf package. Thanks.
The text was updated successfully, but these errors were encountered: