diff --git a/R/metalite_table1_to_rtf.R b/R/metalite_table1_to_rtf.R new file mode 100644 index 0000000..024a666 --- /dev/null +++ b/R/metalite_table1_to_rtf.R @@ -0,0 +1,47 @@ +#' Convert `metalite_table1` to an RTF file +#' +#' @param x Output of `metalite_table1`. +#' @inheritParam r2rtf::write_rtf +#' @inheritParam r2rtf::rtf_title +#' @inheritParam r2rtf::rtf_body +#' +#' @return a string of the RTF file path +#' +#' @export +metalite_table1_to_rtf <- function( + x, + file, + title = "Baseline Characteristics", + rel_width = NULL){ + + # prepare input + tbl <- lapply(tbl[[1]], reactable_to_df) + + colheader <- attr(tbl[[1]], "column_header") + tbl <- do.call(rbind, tbl) + rownames(tbl) <- NULL + + n_col <- ncol(tbl) + + if(is.null(rel_width)){ + rel_width = c(5, rep(2, n_col - 1)) + } + + # output RTF + tbl |> + r2rtf::rtf_title(title) |> + r2rtf::rtf_colheader(colheader, + col_rel_width = rel_width + ) |> + r2rtf::rtf_body( + col_rel_width = rel_width, + text_justification = c("l", rep("c", n_col - 1)), + text_indent_first = -240, + text_indent_left = 180 + ) |> + r2rtf::rtf_encode() |> + r2rtf::write_rtf(file) + + return(file) +} + diff --git a/R/reactable2.R b/R/reactable2.R index c569cf8..ec0554a 100644 --- a/R/reactable2.R +++ b/R/reactable2.R @@ -87,6 +87,7 @@ reactable_to_df <- function(x){ # output tbl <- data.frame(tbl1[, tbl2[["id"]]]) + tbl[, 1] <- gsub("\U2000", " ", tbl[, 1]) attr(tbl, "column_header") <- paste(tbl2$name, collapse = "|") tbl