Skip to content

Commit 8e41c81

Browse files
committed
Add print and format methods for Rcpp_stack_trace
1 parent 4331513 commit 8e41c81

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

NAMESPACE

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ export(Module,
3131
demangle,
3232
sizeof,
3333
cpp_object_initializer,
34-
cpp_object_dummy,
35-
Rcpp.plugin.maker,
36-
str.Rcpp_stack_trace
34+
cpp_object_dummy,
35+
Rcpp.plugin.maker
3736
)
3837
S3method(print, bytes)
38+
S3method(format, Rcpp_stack_trace)
39+
S3method(str, Rcpp_stack_trace)
40+
S3method(print, Rcpp_stack_trace)
3941
exportClass(RcppClass)
4042

4143

R/exceptions.R

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@
3333
warnings
3434
}
3535

36-
str.Rcpp_stack_trace <- function(x, ...) {
37-
cat("\n", paste(collapse = "\n ", x$stack), "\n")
36+
print.Rcpp_stack_trace <- function(x, ...) {
37+
cat(format(x, ...))
38+
}
39+
40+
str.Rcpp_stack_trace <- function(object, ...) {
41+
cat(format(object, ...))
42+
}
43+
44+
format.Rcpp_stack_trace <- function(x, ...) {
45+
paste0(
46+
if (nzchar(x$file)) paste0(x$file, ":", x$line),
47+
"\n ", paste(collapse = "\n ", seq_along(x$stack), ":", x$stack), "\n")
3848
}

0 commit comments

Comments
 (0)