Skip to content

Commit

Permalink
Add new YAML option to remove "Continued on next page..." from long
Browse files Browse the repository at this point in the history
tables spanning multiple pages
* The rmarkdown YAML option value is the default for a new argument in csas_table()
* All templates now contain the new option but it is not required so
old index files will still work
* techreport has a couple of these to test effect
  • Loading branch information
cgrandin committed Jan 6, 2024
1 parent f3d342d commit 6b831db
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 24 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Imports:
knitr,
officer,
purrr,
rlang,
rmarkdown,
stringr,
tibble,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ importFrom(purrr,map_lgl)
importFrom(purrr,prepend)
importFrom(purrr,pwalk)
importFrom(purrr,walk2)
importFrom(rlang,`%||%`)
importFrom(rmarkdown,yaml_front_matter)
importFrom(stringr,str_count)
importFrom(stringr,str_extract_all)
Expand Down
40 changes: 28 additions & 12 deletions R/tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@
#' @param col_names Names for the columns to show on table.
#' @param col_names_align As defined in [kableExtra::linebreak()].
#' @param escape As defined by [kableExtra::kable_styling()].
#' @param hold_position force the table placement to be where the code is called
#' (don't let latex position the table where it wants)
#' @param extra_header character vector of extra headers to be placed above the headers
#' @param ... Other arguments passed to [knitr::kable()] and kableExtra:::pdfTable_add_header_above()
#' @param hold_position force the table placement to be where the code is
#' called (don't let latex position the table where it wants)
#' @param show_continued_text Logical. If `TRUE`, show the
#' 'Continued on next page ...' and '... Continued from previous page'.
#' If this function is called from within an RMarkdown build, this will
#' be set to the value of the YAML option of the same name unless a call
#' to this function within that build supplies this argument as the
#' opposite of the YAML-set value
#' if `format` = "latex"
#' @param extra_header character vector of extra headers to be placed above
#' the headers
#' @param ... Other arguments passed to [knitr::kable()] and
#' kableExtra:::pdfTable_add_header_above()
#' @param ex_bold See `bold` in kableExtra:::pdfTable_add_header_above()
#' @param ex_italic See `italic` in kableExtra:::pdfTable_add_header_above()
#' @param ex_monospace See `monospace` in kableExtra:::pdfTable_add_header_above()
Expand All @@ -31,16 +40,19 @@
#' @param ex_escape See `escape` in kableExtra:::pdfTable_add_header_above()
#' @param ex_line See `line` in kableExtra:::pdfTable_add_header_above()
#' @param ex_line_sep See `line_sep` in kableExtra:::pdfTable_add_header_above()
#' @param cols_no_format A vector of names of numeric columns to not apply `big.mark`
#' and `decimal.mark` to. The function will attempt to detect year columns by default
#' and not apply formatting to those, but this argument, if present, will be added to those
#' @param cols_to_format A vector of the names of columns to format in case they are left
#' unformatted by the year detection algorithm. As long as the columns are numeric,
#' (`is.numeric() == TRUE`), formatting will be applied to these columns
#' @param cols_no_format A vector of names of numeric columns to not
#' apply `big.mark` and `decimal.mark` to. The function will attempt to
#' detect year columns by default and not apply formatting to those, but
#' this argument, if present, will be added to those
#' @param cols_to_format A vector of the names of columns to format in case
#' they are left unformatted by the year detection algorithm. As long as the
#' columns are numeric, (`is.numeric() == TRUE`), formatting will be applied
#' to these columns
#'
#' @importFrom knitr kable
#' @importFrom kableExtra row_spec kable_styling landscape linebreak
#' @importFrom purrr map map2 map_chr map_lgl map_df
#' @importFrom rlang `%||%`
#' @examples
#' csasdown::csas_table(head(iris))
#' @export
Expand All @@ -56,6 +68,8 @@ csas_table <- function(x,
col_names_align = "c",
escape = FALSE,
hold_position = TRUE,
show_continued_text =
rmarkdown::metadata$show_continued_text %||% TRUE,
extra_header = NULL,
ex_bold = FALSE,
ex_italic = FALSE,
Expand Down Expand Up @@ -191,8 +205,10 @@ csas_table <- function(x,
ex_line_sep
)
}
# Insert "Continued on last page for latex
if(format == "latex"){

# Insert `Continued on next page ...` and
# `... Continued from previous page` for latex
if(format == "latex" && show_continued_text){

k_lines <- strsplit(k, "\n")[[1]]

Expand Down
7 changes: 7 additions & 0 deletions inst/rmarkdown/templates/manureport/skeleton/skeleton.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ abstract: |
Here is the abstract text. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
french_abstract: |
Voici le résumé. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
# `show_continued_text` is a logical which, if `true`, places
# "Continued on the next page..." and "...Continued from the previous page" or
# the french equivalents (if `french` = `true`) on all long tables created
# with `csas_table()` that cross page boundaries. If `false`, these will
# both be absent from all tables. If it is missing or any other value than
# `false`, it will be assumed to be `true`
show_continued_text: true
output:
csasdown::manureport_pdf:
french: false
Expand Down
8 changes: 7 additions & 1 deletion inst/rmarkdown/templates/resdoc-b/skeleton/skeleton.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ french_abstract: |
Voici le texte du résumé. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Commencez les nouveaux paragraphes après une ligne blanche et avec un retrait de 2 espaces. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
header: "Draft working paper --- Do not cite or circulate" # or "" to omit
# `show_continued_text` is a logical which, if `true`, places
# "Continued on the next page..." and "...Continued from the previous page" or
# the french equivalents (if `french` = `true`) on all long tables created
# with `csas_table()` that cross page boundaries. If `false`, these will
# both be absent from all tables. If it is missing or any other value than
# `false`, it will be assumed to be `true`
show_continued_text: true
output:
csasdown::resdoc_pdf:
french: false
Expand Down
8 changes: 7 additions & 1 deletion inst/rmarkdown/templates/resdoc/skeleton/skeleton.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ french_abstract: |
Voici le texte du résumé. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Commencez les nouveaux paragraphes après une ligne blanche et avec un retrait de 2 espaces. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
header: "Draft working paper --- Do not cite or circulate" # or "" to omit
# `show_continued_text` is a logical which, if `true`, places
# "Continued on the next page..." and "...Continued from the previous page" or
# the french equivalents (if `french` = `true`) on all long tables created
# with `csas_table()` that cross page boundaries. If `false`, these will
# both be absent from all tables. If it is missing or any other value than
# `false`, it will be assumed to be `true`
show_continued_text: true
output:
csasdown::resdoc_pdf:
french: false
Expand Down
7 changes: 7 additions & 0 deletions inst/rmarkdown/templates/sr/skeleton/skeleton.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ region: Pacific Region
french_region: Région du Pacifique
isbn: "ISBN-Here"
cat_no: "Cat-Number-Here"
# `show_continued_text` is a logical which, if `true`, places
# "Continued on the next page..." and "...Continued from the previous page" or
# the french equivalents (if `french` = `true`) on all long tables created
# with `csas_table()` that cross page boundaries. If `false`, these will
# both be absent from all tables. If it is missing or any other value than
# `false`, it will be assumed to be `true`
show_continued_text: true
output:
csasdown::sr_pdf:
french: false
Expand Down
7 changes: 7 additions & 0 deletions inst/rmarkdown/templates/techreport/skeleton/skeleton.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ abstract: |
Here is the abstract text. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
french_abstract: |
Voici le résumé. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
# `show_continued_text` is a logical which, if `true`, places
# "Continued on the next page..." and "...Continued from the previous page" or
# the french equivalents (if `french` = `true`) on all long tables created
# with `csas_table()` that cross page boundaries. If `false`, these will
# both be absent from all tables. If it is missing or any other value than
# `false`, it will be assumed to be `true`
show_continued_text: true
output:
csasdown::techreport_pdf:
french: false
Expand Down
33 changes: 23 additions & 10 deletions man/csas_table.Rd

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

0 comments on commit 6b831db

Please sign in to comment.