From a38b0a66c9355a504a9f35cb56dd425cd7bffc62 Mon Sep 17 00:00:00 2001 From: Jason Fisher <jfisher@usgs.gov> Date: Fri, 17 Mar 2023 13:57:58 -0700 Subject: [PATCH] add file argument to print_table as recommended by cran --- R/utils.R | 18 ++++++++++++------ inst/tinytest/test_colors.R | 4 ++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/R/utils.R b/R/utils.R index 42a3bc6..4b82bd6 100644 --- a/R/utils.R +++ b/R/utils.R @@ -249,6 +249,7 @@ print_table <- function(d, na = "\\textemdash", rm_dup = NULL, landscape = FALSE, + file = "", ...) { stopifnot(inherits(d, c("matrix", "data.frame"))) @@ -375,6 +376,7 @@ print_table <- function(d, } print_xtable <- xtable::print.xtable + formals(print_xtable)$file <- file formals(print_xtable)$type <- "latex" formals(print_xtable)$caption.placement <- "top" formals(print_xtable)$size <- "\\small" @@ -391,9 +393,9 @@ print_table <- function(d, formals(print_xtable)$comment <- FALSE for (i in seq_along(n)) { - if (i > 1) cat("\n\\clearpage\n") - if (i == 2) cat("\\captionsetup[table]{list=no}\n") - if (landscape) cat("\\begin{landscape}\n") + if (i > 1) cat("\n\\clearpage\n", file = file, append = TRUE) + if (i == 2) cat("\\captionsetup[table]{list=no}\n", file = file, append = TRUE) + if (landscape) cat("\\begin{landscape}\n", file = file, append = TRUE) if (i == 1) { idxs <- 1:n[i] @@ -402,7 +404,7 @@ print_table <- function(d, idxs <- (n[i - 1] + 1):n[i] caption <- sprintf("%s---Continued", cap1) label <- NULL - cat("\\addtocounter{table}{-1}\n") + cat("\\addtocounter{table}{-1}\n", file = file, append = TRUE) } tbl <- d[idxs, ] @@ -444,8 +446,12 @@ print_table <- function(d, print_xtable(x = tbl, hline.after = hline_after, add.to.row = add_to_row, ...) - if (landscape) cat("\\end{landscape}\n") - if (i > 1 && i == length(n)) cat("\\captionsetup[table]{list=yes}\n") + if (landscape) { + cat("\\end{landscape}\n", file = file, append = TRUE) + } + if (i > 1 && i == length(n)) { + cat("\\captionsetup[table]{list=yes}\n", file = file, append = TRUE) + } } invisible() diff --git a/inst/tinytest/test_colors.R b/inst/tinytest/test_colors.R index 7779e4e..be89bcb 100644 --- a/inst/tinytest/test_colors.R +++ b/inst/tinytest/test_colors.R @@ -6,10 +6,10 @@ using("checkmate") # test retrieval of color palettes n <- 10L x <- get_colors(n = n) -checkmate::expect_character(x, len = n, any.missing = FALSE, unique = TRUE) +expect_character(x, len = n, any.missing = FALSE, unique = TRUE) # test setting the hinge location in color palette n <- 19L fun <- set_hinge(x = c(-3, 7), hinge = 0) x <- fun(n) -checkmate::expect_character(x, len = n, any.missing = FALSE, unique = TRUE) +expect_character(x, len = n, any.missing = FALSE, unique = TRUE) -- GitLab