Skip to content

Commit fa4ad10

Browse files
committed
minor linting to match cmdstanr style
1 parent a1f80f4 commit fa4ad10

1 file changed

Lines changed: 18 additions & 20 deletions

File tree

R/run.R

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,8 @@ check_target_exe <- function(exe) {
512512
procs$check_finished()
513513
}
514514
# Ensure at this point that any created progress bar is closed.
515-
if(!is.null(private$progress_bar_)){
516-
private$progress_bar_(type="finish")
515+
if (!is.null(private$progress_bar_)) {
516+
private$progress_bar_(type = "finish")
517517
}
518518
procs$set_total_time(as.double((Sys.time() - start_time), units = "secs"))
519519
procs$report_time()
@@ -731,7 +731,6 @@ CmdStanProcs <- R6::R6Class(
731731
} else {
732732
private$iter_sampling_ <- as.integer(iter_sampling)
733733
}
734-
735734
if (is.null(parallel_procs)) {
736735
private$parallel_procs_ <- private$num_procs_
737736
} else {
@@ -749,22 +748,21 @@ CmdStanProcs <- R6::R6Class(
749748
private$show_stderr_messages_ <- show_stderr_messages
750749
private$show_stdout_messages_ <- show_stdout_messages
751750
private$progress_bar_ <- progress_bar
752-
751+
753752
# Defaults when enabling the progress bar:
754753
# - If 'progress_bar' is set, suppress iteration messages;
755754
# - if `progress_bar` is unset, do not suppress iteration messages;
756755
# - if 'suppress_iteration_messages' is set explicitly, honour that setting.
757-
if(is.null(progress_bar)) {
756+
if (is.null(progress_bar)) {
758757
private$suppress_iteration_messages_ <- FALSE
759758
} else {
760759
private$suppress_iteration_messages_ <- TRUE
761760
}
762-
if(!is.null(suppress_iteration_messages)) {
761+
if (!is.null(suppress_iteration_messages)) {
763762
private$suppress_iteration_messages_ <- suppress_iteration_messages
764763
}
765764

766-
if(is.null(refresh)) {
767-
# Default to Stan default of 100 if refresh not set explicitly.
765+
if (is.null(refresh)) {
768766
private$refresh_ <- 100
769767
} else {
770768
private$refresh_ <- refresh
@@ -1113,50 +1111,50 @@ CmdStanMCMCProcs <- R6::R6Class(
11131111
|| grepl("stancflags", line, fixed = TRUE)) {
11141112
ignore_line <- TRUE
11151113
}
1116-
# Update progress bar
1114+
# Update progress bar
11171115
if (!ignore_line && !is.null(private$progress_bar_)) {
11181116
# Pass the current output line to the progress bar as a message,
11191117
# but only update the progress bar if the current line is an
11201118
# iteration message.
11211119
progress_amount <- 0
1122-
if(grepl("Iteration:", line, perl = TRUE)) {
1120+
if (grepl("Iteration:", line, perl = TRUE)) {
11231121
# Calculating the amount by which to increment the progress bar
11241122
# is more complicated than it initially seems, due to occasional
11251123
# extra or awkward iteration reporting messages when starting
11261124
# sampling, moving from warmup to sampling, reaching the end of
11271125
# sampling where the number of samples is not a multiple of the
11281126
# refresh_rate.
11291127

1130-
# Strategy:
1128+
# Strategy:
11311129
# If the line's iteration value is divisible by refresh_rate, or
11321130
# is the final sampling step, update the progress bar by
11331131
# refresh_rate.
1134-
1132+
11351133
# Additionally, when moving from warmup to sampling, iterations
11361134
# are reported starting from a baseline of the number of warmup
11371135
# iterations. (For example, if refresh_rate is 12 and iter_warmup
11381136
# is 100, the first reported iteration for sampling will be 112,
11391137
# not 108.)
1140-
1138+
11411139
# Get the current iteration count.
11421140
# Subtract iter_warmup if greater than that.
1143-
iter_current <- as.numeric(gsub( ".*Iteration:\\s*([0-9]+) \\/.*", "\\1", line, perl=TRUE ))
1144-
if( iter_current > private$iter_warmup_ ) {
1141+
iter_current <- as.numeric(gsub(".*Iteration:\\s*([0-9]+) \\/.*", "\\1", line, perl = TRUE))
1142+
if (iter_current > private$iter_warmup_) {
11451143
iter_current <- iter_current - private$iter_warmup_
11461144
}
11471145

11481146
# Update progress bar if the iteration is a multiple of the
11491147
# refresh rate, or is the final sampling iteration.
1150-
if(((iter_current %% private$refresh_) == 0) |
1151-
iter_current == private$iter_warmup_ + private$iter_sampling_) {
1148+
if (((iter_current %% private$refresh_) == 0) ||
1149+
iter_current == private$iter_warmup_ + private$iter_sampling_) {
11521150
progress_amount <- private$refresh_
1153-
}
1151+
}
11541152
}
1155-
private$progress_bar_(amount=progress_amount, message=line)
1153+
private$progress_bar_(amount = progress_amount, message = line)
11561154
}
11571155
# Allow suppression of iteration messages
11581156
if (private$suppress_iteration_messages_) {
1159-
if(grepl("Iteration:", line, perl = TRUE)) {
1157+
if (grepl("Iteration:", line, perl = TRUE)) {
11601158
ignore_line <- TRUE
11611159
}
11621160
}

0 commit comments

Comments
 (0)