diff --git a/R/model.R b/R/model.R index f9b8241c..f2c133cc 100644 --- a/R/model.R +++ b/R/model.R @@ -302,7 +302,16 @@ CmdStanModel <- R6::R6Class( if (length(private$stan_code_) == 0) { stop("'$print()' cannot be used because the 'CmdStanModel' was not created with a Stan file.", call. = FALSE) } - cat(self$code(), sep = "\n") + lines <- self$code() + line_num_indent <- nchar(as.character(length(lines))) + line_nums <- vapply(seq_along(lines), function(y) { + paste0( + rep(" ", line_num_indent - nchar(as.character(y))), y, collapse = "" + ) + }, character(1)) + cat( + paste(paste(line_nums, lines, sep = ": "), collapse = "\n"), sep = "\n" + ) invisible(self) }, stan_file = function() {