Skip to content

Commit 3eaa74e

Browse files
committed
make line number printing optional
1 parent a74e51a commit 3eaa74e

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

R/model.R

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -298,20 +298,21 @@ CmdStanModel <- R6::R6Class(
298298
}
299299
private$stan_code_
300300
},
301-
print = function() {
301+
print = function(line_numbers = getOption("cmdstanr_print_line_numbers", FALSE)) {
302302
if (length(private$stan_code_) == 0) {
303303
stop("'$print()' cannot be used because the 'CmdStanModel' was not created with a Stan file.", call. = FALSE)
304304
}
305305
lines <- self$code()
306-
line_num_indent <- nchar(as.character(length(lines)))
307-
line_nums <- vapply(seq_along(lines), function(y) {
308-
paste0(
309-
rep(" ", line_num_indent - nchar(as.character(y))), y, collapse = ""
310-
)
311-
}, character(1))
312-
cat(
313-
paste(paste(line_nums, lines, sep = ": "), collapse = "\n"), sep = "\n"
314-
)
306+
if (line_numbers) {
307+
line_num_indent <- nchar(as.character(length(lines)))
308+
line_nums <- vapply(seq_along(lines), function(y) {
309+
paste0(
310+
rep(" ", line_num_indent - nchar(as.character(y))), y, collapse = ""
311+
)
312+
}, character(1))
313+
lines <- paste(paste(line_nums, lines, sep = ": "), collapse = "\n")
314+
}
315+
cat(lines, sep = "\n")
315316
invisible(self)
316317
},
317318
stan_file = function() {

0 commit comments

Comments
 (0)