diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 9309e32c..051f7643 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -65,8 +65,7 @@ jobs: R -q -e 'remotes::install_version("Hmisc", "4.5-0")' R -q -e 'remotes::install_github("FredHutch/VISCfunctions", dependencies = TRUE)' R -q -e 'remotes::install_github("FredHutch/VISCtemplates", dependencies = TRUE)' - R -q -e 'utils::install.packages(c("ggplot2", "dplyr"))' - R -q -e 'utils::install.packages("rcmdcheck")' + R -q -e 'utils::install.packages(c("rcmdcheck", "ggplot2", "dplyr", "flextable"))' - uses: r-lib/actions/setup-r-dependencies@v2 if: ${{ matrix.config.r != '4.0.4' }} diff --git a/DESCRIPTION b/DESCRIPTION index f18fc5d9..8e8aabd3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -46,9 +46,10 @@ Roxygen: list(markdown = TRUE) Suggests: conflicted, dplyr, + flextable, ggplot2, - kableExtra, knitr, + officer, remotes, testthat (>= 3.0.0), withr diff --git a/inst/rmarkdown/templates/visc_empty/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/visc_empty/skeleton/skeleton.Rmd index 5e3deae4..31eaf868 100644 --- a/inst/rmarkdown/templates/visc_empty/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/visc_empty/skeleton/skeleton.Rmd @@ -23,8 +23,8 @@ lot: true toc: true dropVISClogo: false output: - VISCtemplates::visc_pdf_document: default VISCtemplates::visc_word_document: default + VISCtemplates::visc_pdf_document: default --- -```{r study-schema, results="asis", warning=kable_warnings} +```{r} source(rprojroot::find_rstudio_root_file("R", "study_schema.R"), local = TRUE) -study_schema() +flextable(schema_table) %>% + add_caption_and_label("[CAVD PI and number] study schema", "study-schema") ``` Describe this report - "This report presents [blinded/unblinded] [list assay] data @@ -216,15 +220,7 @@ response_results <- ICS_adata %>% verbose = FALSE ) ) %>% - ungroup() %>% - mutate( - ResponseTest = pretty_pvalues( - ResponseTest, output_type = output_type, sig_alpha = .1, - background = 'yellow', - bold = if_else(pandoc_markup , TRUE, FALSE), - italic = if_else(pandoc_markup , TRUE, FALSE) - ) - ) + ungroup() ``` ```{r magnitude-testing, warning=FALSE} @@ -245,14 +241,7 @@ magnitude_results <- ICS_adata %>% ) ) %>% ungroup() %>% - mutate( - MagnitudeTest = pretty_pvalues( - MagnitudeTest, output_type = output_type, sig_alpha = .1, - background = "yellow", - bold = if_else(pandoc_markup , TRUE, FALSE), - italic = if_else(pandoc_markup , TRUE, FALSE) - ) - ) %>% + mutate(MagnitudeTest = round(MagnitudeTest, 3)) %>% rename("Median (Range)" = Median_Min_Max, 'Mean (SD)' = Mean_SD) ``` @@ -329,65 +318,51 @@ ICS_adata %>% \newpage -```{r example-tab, results="asis", warning=kable_warnings} - -magnitude_tab <- magnitude_results %>% - select(-Population, -contains("Perfect")) - -caption_short <- "Short caption to show in List of Tables." - -caption <- "Long caption to show above table. Explain everything needed to understand the table here." - -magnitude_tab %>% - kable( - format = output_type, - longtable = FALSE, - booktabs = TRUE, - linesep = "", - escape = FALSE, - caption.short = caption_short, - caption = caption - ) %>% - kable_styling( - font_size = 8, - # Note scale_down will overwrite font_size specifications - latex_options = c("hold_position", "scale_down", "repeat_header") - ) %>% - collapse_rows( - columns = 1:2, - row_group_label_position = "identity", - latex_hline = "full" - ) %>% - footnote("SD: standard deviation.", threeparttable = TRUE) +```{r} + +label <- "example-tab" +caption <- "Example caption (should be short but specific, as it will be used in list of tables)" +footnotes <- c("SD: standard deviation.", + "Any other details needed to understand the table.") + +magnitude_results %>% + select(-Population, -contains("Perfect")) %>% + flextable() %>% + fontsize(size = 7) %>% + merge_v(1:2) %>% + width(1, 0.4, unit = "in") %>% + width(2, 0.4, unit = "in") %>% + highlight(i = ~ (MagnitudeTest < 0.05), j = ~ MagnitudeTest, color = "yellow") %>% + add_footer_lines(values = footnotes) %>% + add_caption_and_label(caption, label) ``` \newpage -```{r Software-Session-Information, results="asis", message=FALSE, warning=kable_warnings} -# load in rmarkdown to capture verison number +```{r} + +label <- "Software-Session-Information" +caption <- "Reproducibility software session information" + +# load in rmarkdown to capture version number if (any(installed.packages()[,1] == 'rmarkdown')) suppressWarnings(library(rmarkdown)) my_session_info <- VISCfunctions::get_session_info() -kable( - my_session_info$platform_table, - format = output_type, - booktabs = TRUE, - linesep = "", - caption = "Reproducibility software session information" - ) %>% - kable_styling(font_size = 10, latex_options = "hold_position") +flextable(my_session_info$platform_table) %>% + add_caption_and_label(caption, label) %>% + width(2, 6, unit = "in") ``` -```{r Software-Package-Version-Information, results="asis", warning=kable_warnings} -kable( - my_session_info$packages_table, - format = output_type, - booktabs = TRUE, - linesep = "", - caption = "Reproducibility software package version information" - ) %>% - kable_styling(font_size = 10, latex_options = "hold_position") +\newpage + +```{r} + +label <- "Software-Package-Version-Information" +caption <- "Reproducibility software package version information" + +flextable(my_session_info$packages_table) %>% + add_caption_and_label(caption, label) ``` \newpage diff --git a/inst/templates/study_schema.R b/inst/templates/study_schema.R index f38b8608..18afeb3b 100644 --- a/inst/templates/study_schema.R +++ b/inst/templates/study_schema.R @@ -2,27 +2,9 @@ #' #' To source the study schema in a chunk in your Rmarkdown report: #' source("R/study_schema.R", local = TRUE) -#' -#' @param caption caption for the study schema table -#' -#' @return a kable table with the study schema -#' @export -#' -#' @examples -study_schema <- function(caption = "{{ study_name }} study schema.") { - - schema_table <- tibble::tribble( - ~Group, ~`Sample Size`, ~`Week 10`, ~`Week 20`, - "Group A", 10, "Dose A", "Dose A", - "Group B", 10, "Dose B", "Dose B" - ) - schema_table %>% - knitr::kable( - format = VISCtemplates::get_output_type(), - caption = caption, - booktabs = TRUE, - linesep = "" - ) %>% - kableExtra::kable_styling(latex_options = c("hold_position")) - } +schema_table <- tibble::tribble( + ~Group, ~`Sample Size`, ~`Week 10`, ~`Week 20`, + "Group A", 10, "Dose A", "Dose A", + "Group B", 10, "Dose B", "Dose B" +)