Skip to content

Commit

Permalink
import flextable
Browse files Browse the repository at this point in the history
  • Loading branch information
DanChaltiel committed Nov 22, 2024
1 parent 2828866 commit 925661b
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 35 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Depends:
Imports:
cli,
dplyr,
flextable,
forcats,
fs,
ggplot2,
Expand All @@ -43,7 +44,6 @@ Imports:
Suggests:
callr,
crosstable,
flextable,
gtools,
patchwork,
plotly,
Expand Down
4 changes: 3 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Generated by roxygen2: do not edit by hand

S3method(flextable::as_flextable,ae_table_soc)
S3method(as_flextable,ae_table_soc)
export("%>%")
export(ae_plot_grade)
export(ae_plot_grade_n)
export(ae_plot_grade_sum)
export(ae_plot_soc)
export(ae_table_grade)
export(ae_table_soc)
export(as_flextable)
export(butterfly_plot)
export(fct_yesno)
export(gr_new_project)
Expand Down Expand Up @@ -52,6 +53,7 @@ importFrom(dplyr,setdiff)
importFrom(dplyr,setequal)
importFrom(dplyr,summarise)
importFrom(dplyr,transmute)
importFrom(flextable,as_flextable)
importFrom(forcats,as_factor)
importFrom(forcats,fct_infreq)
importFrom(forcats,fct_relevel)
Expand Down
6 changes: 1 addition & 5 deletions R/ae_table_grade.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
#' tm = grstat_example()
#' attach(tm, warn.conflicts=FALSE)
#'
#' if(require(flextable)){
#'
#' ae_table_grade(df_ae=ae, df_enrol=enrolres, arm=NULL) %>%
#' as_flextable(header_show_n=TRUE)
#'
Expand All @@ -38,10 +36,8 @@
#' ae %>%
#' filter(sae=="Yes") %>%
#' ae_table_grade(df_enrol=enrolres, arm="ARM") %>%
#' dplyr::mutate_all(~stringr::str_replace(.x, "AE", "SAE")) %>%
#' mutate_all(~stringr::str_replace(.x, "AE", "SAE")) %>%
#' as_flextable(header_show_n=TRUE)
#'
#' }
ae_table_grade = function(
df_ae, ..., df_enrol,
variant=c("max", "sup", "eq"),
Expand Down
37 changes: 17 additions & 20 deletions R/ae_table_soc.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
#' #sub population
#' ae_table_soc(df_ae=ae, df_enrol=head(enrolres, 10), arm="arm")
#'
#' if (require("flextable")) {
#'
#' #the resulting flextable can be customized using the flextable package
#' ae_table_soc(ae, df_enrol=enrolres, total=FALSE) %>%
#' as_flextable() %>%
Expand All @@ -60,7 +58,6 @@
#' ae_table_soc(ae, df_enrol=enrolres, term=NULL, arm=NULL) %>%
#' as_flextable() %>%
#' highlight(i=~soc=="Hepatobiliary disorders", j="all_patients_Tot")
#' }
ae_table_soc = function(
df_ae, ..., df_enrol,
variant=c("max", "sup", "eq"),
Expand Down Expand Up @@ -171,6 +168,7 @@ ae_table_soc = function(
#' @return a formatted flextable
#' @rdname ae_table_soc
#' @exportS3Method flextable::as_flextable
#' @export
#'
#' @importFrom dplyr case_match lag lead transmute
#' @importFrom purrr map map_int
Expand All @@ -181,7 +179,6 @@ ae_table_soc = function(
as_flextable.ae_table_soc = function(x,
arm_colors=c("#f2dcdb", "#dbe5f1", "#ebf1dd", "#e5e0ec"),
padding_v = NULL){
check_installed("flextable")
if (missing(padding_v)) padding_v = getOption("crosstable_padding_v", padding_v)
table_ae_header = attr(x, "header")
if(FALSE){
Expand Down Expand Up @@ -221,31 +218,31 @@ as_flextable.ae_table_soc = function(x,
which() %>% unname() %>% c(ncol(x))

rtn = x %>%
flextable::flextable() %>%
flextable::set_header_df(mapping=header_df) %>%
# flextable::hline_top(part="header") %>%
flextable::hline_bottom(part="header") %>%
flextable::merge_h(part="header") %>%
# flextable::set_header_labels(values=header_labels) %>%
# flextable::add_header_row(values=c(" ", table_ae_header), colwidths = colwidths) %>%
flextable::align(i=1, part="header", align="center") %>%
flextable::align(j=seq(col1), part="all", align="right") %>%
flextable::padding(padding.top=0, padding.bottom=0) %>%
flextable::set_table_properties(layout="autofit") %>%
flextable::fontsize(size=8, part="all") %>%
flextable::bold(part="header")
flextable() %>%
set_header_df(mapping=header_df) %>%
# hline_top(part="header") %>%
hline_bottom(part="header") %>%
merge_h(part="header") %>%
# set_header_labels(values=header_labels) %>%
# add_header_row(values=c(" ", table_ae_header), colwidths = colwidths) %>%
align(i=1, part="header", align="center") %>%
align(j=seq(col1), part="all", align="right") %>%
padding(padding.top=0, padding.bottom=0) %>%
set_table_properties(layout="autofit") %>%
fontsize(size=8, part="all") %>%
bold(part="header")
if (length(padding_v) >= 1) {
rtn = flextable::padding(rtn, padding.top=padding_v[1], padding.bottom=padding_v[1], part="body")
rtn = padding(rtn, padding.top=padding_v[1], padding.bottom=padding_v[1], part="body")
}
if (length(padding_v) == 2) {
rtn = flextable::padding(rtn, padding.top=padding_v[2], padding.bottom=padding_v[2], part="header")
rtn = padding(rtn, padding.top=padding_v[2], padding.bottom=padding_v[2], part="header")
}
# a = cumsum(colwidths)[-1]
a = sep_cols
for(i in seq_along(a)){
from = lag(a, default=col1)[i] + 1
to = a[i]
rtn = rtn %>% flextable::bg(j=seq(from, to), bg = arm_colors[i], part="all")
rtn = rtn %>% bg(j=seq(from, to), bg = arm_colors[i], part="all")
}

rtn
Expand Down
3 changes: 3 additions & 0 deletions R/grstat-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ dplyr::`%>%`
#' @export
tibble::tibble

#' @importFrom flextable as_flextable
#' @export
flextable::as_flextable

# Global settings -----------------------------------------------------------------------------

Expand Down
6 changes: 1 addition & 5 deletions man/ae_table_grade.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions man/ae_table_soc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/reexports.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 925661b

Please sign in to comment.