Skip to content

Commit

Permalink
print line numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
sbfnk committed May 10, 2024
1 parent c3d0168 commit f178a44
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit f178a44

Please sign in to comment.