Skip to content

Commit

Permalink
attempt to close #238 (#242)
Browse files Browse the repository at this point in the history
```
> library(rlistings)
Loading required package: formatters

Attaching package: ‘formatters’

The following object is masked from ‘package:base’:

    %||%

Loading required package: tibble
> result <- tibble::tibble(col1 = character(0L), col2 = character(0L), col3 = character(0L))
> 
> listing <- rlistings::as_listing(result)
> 
> sprintf("Rows: %d // Columns: %d", nrow(listing), ncol(listing))
[1] "Rows: 0 // Columns: 3"
> 
> print(listing)
[1] "No observation in the listing object."
```

---------

Signed-off-by: Joe Zhu <sha.joe.zhu@gmail.com>
Co-authored-by: André Veríssimo <211358+averissimo@users.noreply.github.com>
  • Loading branch information
shajoezhu and averissimo authored Jan 7, 2025
1 parent ceca6ef commit 9c050e1
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions R/rlistings_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 9c050e1

Please sign in to comment.