Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve word doc formatting #212

Draft
wants to merge 54 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
4b13b10
update word document template
kelliemac May 31, 2024
4926de5
try editing cslreferences
kelliemac May 31, 2024
fdb23cc
update cslreferences with latest pandoc template
kelliemac May 31, 2024
5bc3417
simplify
kelliemac May 31, 2024
18ed57c
simplify and add comments
kelliemac May 31, 2024
ed59187
fix space between references
kelliemac May 31, 2024
02e1775
try out cslreferences without arguments
kelliemac Jun 1, 2024
65ca9a8
go back to cslreferences with two arguments, and add explanatory comment
kelliemac Jun 1, 2024
cdc423a
comment out reserveinserts because giving errors
kelliemac Jun 5, 2024
a7159ed
update word doc template to be more consistent with pdf
kelliemac Jun 6, 2024
5f3718f
improve word doc header and footer
kelliemac Jun 6, 2024
7a8bf09
improve table of contents formatting and empty space before table cap…
kelliemac Jun 7, 2024
f636841
spring cleaning of template.tex
kelliemac Jun 13, 2024
151cc0e
update date and author fields to be more consistent with pdf format
kelliemac Jun 13, 2024
1959ec5
update author and date formatting to further match pdf formatting
kelliemac Jun 13, 2024
a4c7267
merge develop into kellie/c101
kelliemac Jul 11, 2024
b496014
undo changes to csl references section
kelliemac Jul 12, 2024
0528d97
whoops last commit did the wrong thing, revert and actually do what I…
kelliemac Jul 12, 2024
bc1871e
try adding table printing function
kelliemac Jul 12, 2024
28f095c
bug fixes for table generation
kelliemac Jul 12, 2024
4367cab
add documentation for new function and import pipe
kelliemac Jul 12, 2024
d81218b
add flextable
slager Jul 18, 2024
3145566
Merge branch 'develop' into kellie/c101
slager Jul 18, 2024
56b7ace
add missing label
slager Jul 18, 2024
b1f1071
use built-in escaping
slager Jul 18, 2024
d69c4ed
revert changes to latex template
kelliemac Jul 22, 2024
b87e25b
Merge branch 'develop' into kellie/c101, except Word template
slager Jul 22, 2024
3b13d36
add extra whitespace to rm file from diff
slager Jul 22, 2024
af1df1b
Merge branch 'develop' into improve-word-doc-formatting
kelliemac Jul 24, 2024
0a8c348
switch over to using flextable for both word and pdf outputs
kelliemac Jul 24, 2024
38ab940
document package
kelliemac Jul 24, 2024
a811c43
add pipe documentation
kelliemac Jul 25, 2024
3a4d395
add labels to flextables
kelliemac Jul 25, 2024
952ad3e
remove output_type designations and use rmarkdown style tab.id and ta…
kelliemac Jul 25, 2024
4acb754
update dependencies
kelliemac Jul 25, 2024
8a7aae7
use officer::autonum to generate table labels
kelliemac Jul 25, 2024
8cfc426
format table widths to fit on page and add highlighting of small p va…
kelliemac Jul 25, 2024
f907f6e
change background cell color to highlight
kelliemac Jul 25, 2024
49c13ff
make study schema render as a flextable
kelliemac Jul 25, 2024
1ba5b4b
remove extraneous code edits
kelliemac Jul 25, 2024
3276eb3
Merge branch 'develop' into improve-word-doc-formatting
kelliemac Jul 25, 2024
222068a
remove TODO for caption details and undo accidental deletion of comme…
kelliemac Jul 25, 2024
ea15514
use as_paragraph instead of regular list
kelliemac Jul 25, 2024
f14b72a
fix bugs from web-based merge of develop branch
kelliemac Jul 25, 2024
802b16a
actually fix the bug with chunking ending in wrong place
kelliemac Jul 25, 2024
f195f0c
update header logos
kelliemac Jul 25, 2024
bd64dac
Merge branch 'develop' into improve-word-doc-formatting
kelliemac Jul 25, 2024
35aac10
udpate study schema file to allow captioning and labeling in Rmd instead
kelliemac Jul 25, 2024
27a22e3
Merge branch 'improve-word-doc-formatting' of github.com:FredHutch/VI…
kelliemac Jul 25, 2024
923cfb1
functionalize table labelling, and fix example footnote layout
kelliemac Jul 25, 2024
ce919d2
rename add_caption function to add_caption_and_label for better clarity"
kelliemac Jul 25, 2024
42edf44
remove results=asis for table chunks
kelliemac Jul 25, 2024
2d25d4f
order suggests in description alphabetically
kelliemac Jul 25, 2024
055f832
update visc logo in word document header
kelliemac Jul 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
Expand Down
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ Roxygen: list(markdown = TRUE)
Suggests:
conflicted,
dplyr,
flextable,
ggplot2,
kableExtra,
knitr,
officer,
remotes,
testthat (>= 3.0.0),
withr
Expand Down
62 changes: 31 additions & 31 deletions inst/rmarkdown/templates/visc_empty/skeleton/skeleton.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
---

<!---
Expand All @@ -47,7 +47,7 @@ library(VISCfunctions)
check_pandoc_version()

# packages installed from CRAN
packages_needed <- c("conflicted", "dplyr", "knitr", "kableExtra", "rprojroot")
packages_needed <- c("conflicted", "dplyr", "ggplot2", "knitr", "flextable", "rprojroot")
install_load_cran_packages(packages_needed)

# knitr options
Expand All @@ -65,8 +65,18 @@ if (knitr::opts_knit$get('rmarkdown.pandoc.to') == 'latex'){
opts_chunk$set(fig.align = "center")
}

# NA's will be blank in tables
options(knitr.kable.NA = '')
# Table settings
set_flextable_defaults(na_str = "", # NA's will be blank in tables
font.size = 8,
theme_fun = "theme_vanilla",
table.layout = "autofit",
digits = 3,
fonts_ignore = TRUE)
add_caption_and_label <- function(x, caption, label) {
set_caption(x,
caption = caption,
autonum = officer::run_autonum(seq_id = "tab", bkm = label))
}

# Create a ggplot theme for consistency of figures
visc_theme <- theme_bw() +
Expand All @@ -82,14 +92,6 @@ theme_set(visc_theme)
conflict_prefer("filter", "dplyr")
```

```{r word-pdf-options}

output_type <- get_output_type()

kable_warnings <- set_kable_warnings(output_type)
pandoc_markup <- set_pandoc_markup(output_type)
```

```{r read-data}

# Read in your data in this chunk
Expand All @@ -116,31 +118,29 @@ Add some text here

# Reproducibility Software Information

```{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)
```

```{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
Expand Down
5 changes: 5 additions & 0 deletions inst/rmarkdown/templates/visc_report/resources/template.tex
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
\usepackage{threeparttable} % provides a scheme for tables that have a structured (foot)note section, after the caption
\usepackage{threeparttablex} % provides the functionality of the threeparttable package to tables created using the longtable package

% needed for flextable to work
\usepackage{hhline}
\newlength\Oldarrayrulewidth
\newlength\Oldtabcolsep

% being able to set emphasis for entire table row
\newcommand\setrow[1]{\gdef\rowmac{#1}#1\ignorespaces}
\newcommand\clearrow{\global\let\rowmac\relax}
Expand Down
Binary file not shown.
133 changes: 54 additions & 79 deletions inst/rmarkdown/templates/visc_report/skeleton/skeleton.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ library(VISCfunctions)
check_pandoc_version()

# packages installed from CRAN
packages_needed <- c("conflicted", "ggplot2", "dplyr", "knitr", "kableExtra", "rprojroot", "remotes")
packages_needed <- c("conflicted", "ggplot2", "dplyr", "knitr", "flextable", "rprojroot", "remotes")
install_load_cran_packages(packages_needed)

# where to install and look for packages (e.g., data packages) installed on SCHARP server
Expand All @@ -69,8 +69,19 @@ if (knitr::opts_knit$get('rmarkdown.pandoc.to') == 'latex'){
opts_chunk$set(fig.align = "center")
}

# NA's will be blank in tables
options(knitr.kable.NA = '')

# table settings
set_flextable_defaults(na_str = "", # NA's will be blank in tables
font.size = 8,
theme_fun = "theme_vanilla",
table.layout = "autofit",
digits = 3,
fonts_ignore = TRUE)
add_caption_and_label <- function(x, caption, label) {
set_caption(x,
caption = caption,
autonum = officer::run_autonum(seq_id = "tab", bkm = label))
}

# Create a ggplot theme for consistency of figures
visc_theme <- theme_bw() +
Expand All @@ -95,14 +106,6 @@ group_colors <- c(
conflict_prefer("filter", "dplyr")
```

```{r word-pdf-options}

output_type <- get_output_type()

kable_warnings <- set_kable_warnings(output_type)
pandoc_markup <- set_pandoc_markup(output_type)
```

```{r data-package, eval=FALSE}

# note: set_wd() only impacts this code chunk
Expand Down Expand Up @@ -147,9 +150,10 @@ be used across PT reports for the protocol. -->

<!-- Also include the study schema here. -->

```{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
Expand Down Expand Up @@ -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}
Expand All @@ -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)
```

Expand Down Expand Up @@ -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
Expand Down
28 changes: 5 additions & 23 deletions inst/templates/study_schema.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Loading