Skip to content

Commit

Permalink
Fix print() when 'quote' or 'right' are provided
Browse files Browse the repository at this point in the history
Calling print.xts() with either of these arguments specified would throw
an error. Thanks to @WillemMaetens for the report and patch!

Fixes #401.
  • Loading branch information
joshuaulrich committed Jul 9, 2023
1 parent fcb0ba8 commit a2c7520
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 7 additions & 6 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions inst/tinytest/test-print.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit a2c7520

Please sign in to comment.