diff --git a/R/rlistings_methods.R b/R/rlistings_methods.R index d5ca8d6f..cc5a3e36 100644 --- a/R/rlistings_methods.R +++ b/R/rlistings_methods.R @@ -15,17 +15,25 @@ dflt_courier <- font_spec("Courier", 9, 1) #' @export #' @name listing_methods print.listing_df <- function(x, widths = NULL, tf_wrap = FALSE, max_width = NULL, fontspec = NULL, col_gap = 3L, ...) { - cat( - toString( - matrix_form(x, fontspec = fontspec, col_gap = col_gap), - widths = widths, - tf_wrap = tf_wrap, - max_width = max_width, - fontspec = fontspec, - col_gap = col_gap, - ... + tryCatch({ + cat( + toString( + matrix_form(x, fontspec = fontspec, col_gap = col_gap), + widths = widths, + tf_wrap = tf_wrap, + max_width = max_width, + fontspec = fontspec, + col_gap = col_gap, + ... + ) ) - ) + }, error = function(e) { + if (nrow(x) == 0) { + print("No observation in the listing object.") + } else { + stop(e) + } + }) invisible(x) }