From a2c75204190f2c9f0aa2d566ae6450e937b8e054 Mon Sep 17 00:00:00 2001 From: Joshua Ulrich Date: Sun, 9 Jul 2023 09:30:23 -0500 Subject: [PATCH] Fix print() when 'quote' or 'right' are provided Calling print.xts() with either of these arguments specified would throw an error. Thanks to @WillemMaetens for the report and patch! Fixes #401. --- R/print.R | 13 +++++++------ inst/tinytest/test-print.R | 6 ++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/R/print.R b/R/print.R index 3c4a1f60..404eac96 100644 --- a/R/print.R +++ b/R/print.R @@ -30,6 +30,8 @@ print.xts <- nr <- NROW(x) nc <- NCOL(x) + dots <- list(...) + if (missing(max.rows)) { # the user didn't specify a value; use the global option value if it's # set; if it's not set, use the default value @@ -43,9 +45,8 @@ print.xts <- show.rows <- 0 } else { # convert 'max' to 'show.rows' - max.arg <- match.call()$max - if (!is.null(max.arg)) { - show.rows <- trunc(max.arg / nc) + if (!is.null(dots$max)) { + show.rows <- trunc(dots$max / nc) } } } else if (missing(show.rows)) { @@ -62,10 +63,10 @@ print.xts <- } if (!hasArg("quote")) { - quote <- FALSE + dots$quote <- FALSE } if (!hasArg("right")) { - right <- TRUE + dots$right <- TRUE } if (nr > max.rows && nr > 2 * show.rows) { @@ -127,7 +128,7 @@ print.xts <- colnames(y) <- paste0("[,", seq_len(ncol(y)), "]") } - print(y, quote = quote, right = right, ...) + do.call("print", c(list(y), dots)) } invisible(x) diff --git a/inst/tinytest/test-print.R b/inst/tinytest/test-print.R index 01251cdd..85d2596b 100644 --- a/inst/tinytest/test-print.R +++ b/inst/tinytest/test-print.R @@ -40,3 +40,9 @@ expect_identical(p, x, info = "returns input invisibly") z <- .xts(matrix(0, nrow = 200, ncol = 200), 1:200) expect_silent(print(z), info = "print more columns than width doesn't error") + +expect_silent(print(x, quote = TRUE), + info = "print.xts() does not error when 'quote' argument is used") + +expect_silent(print(x, right = TRUE), + info = "print.xts() does not error when 'right' argument is used")