Skip to content

Commit

Permalink
More use of withr. Rename a few functions to replace . with _
Browse files Browse the repository at this point in the history
  • Loading branch information
MLopez-Ibanez committed Dec 9, 2024
1 parent ea2a71e commit 7c8cd1b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion R/configurations.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ configurations_alloc <- function(colnames, nrow, parameters)
r = NA_real_,
c = NA_character_,
o = NA_character_,
irace.internal.error("Unknown type '", type, "'"))
irace_internal_error("Unknown type '", type, "'"))
}

column_type <- function(x, n, types)
Expand Down
2 changes: 1 addition & 1 deletion R/generation.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ generate_sobol <- function(parameters, n, repair = NULL)
r = NA_real_,
c = NA_character_,
o = NA_character_,
irace.internal.error("Unknown type '", param[["type"]], "'"))
irace_internal_error("Unknown type '", param[["type"]], "'"))
set(confs, j = p, value = na_value)
}
}
Expand Down
12 changes: 6 additions & 6 deletions R/irace.R
Original file line number Diff line number Diff line change
Expand Up @@ -612,16 +612,16 @@ irace <- function(scenario)
irace_common <- function(scenario, simple, output.width = 9999L)
{
if (!simple) {
op <- options(width = output.width) # Do not wrap the output.
on.exit(options(op), add = TRUE)
withr::local_options(width = output.width) # Do not wrap the output.
}
scenario <- checkScenario(scenario)
debugLevel <- scenario$debugLevel

if (debugLevel >= 1) {
op.debug <- options(warning.length = 8170)
if (!base::interactive()) options(error = irace.dump.frames)
on.exit(options(op.debug), add = TRUE)
if (debugLevel >= 1L) {
op <- list(warning.length = 8170L)
if (!base::interactive())
op <- c(op, list(error = irace_dump_frames))
withr::local_options(op)
printScenario (scenario)
}

Expand Down
2 changes: 1 addition & 1 deletion R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ initialiseModel <- function (parameters, configurations)
sd <- (length(domain) - 1L) * 0.5
values <- match(configurations[[currentParameter]], domain)
} else {
irace.internal.error("Unknown parameter type '", type, "'")
irace_internal_error("Unknown parameter type '", type, "'")
}
# Assign current parameter value to model.
param <- mapply(c, sd, values, SIMPLIFY=FALSE, USE.NAMES=FALSE)
Expand Down
15 changes: 8 additions & 7 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ irace.error <- function(...)
## R> debugger(iracedump)
##
## See help(dump.frames) for more details.
irace.dump.frames <- function()
irace_dump_frames <- function()
{
execDir <- getOption(".irace.execdir")
if (!is.null(execDir)) cwd <- setwd(execDir)
Expand All @@ -34,15 +34,16 @@ irace.dump.frames <- function()
}

# Print an internal fatal error message that signals a bug in irace.
irace.internal.error <- function(...)
irace_internal_error <- function(...)
{
.irace.bug.report <-
paste0(.irace_msg_prefix, "An unexpected condition occurred. ",
"Please report this bug to the authors of the irace package <https://github.com/MLopez-Ibanez/irace/issues>")

op <- options(warning.length = 8170)
if (!base::interactive()) options(error = irace.dump.frames)
on.exit(options(op))
op <- list(warning.length = 8170L)
if (!base::interactive())
op <- c(op, list(error = irace_dump_frames))
withr::local_options(op)
# 6 to not show anything below irace.assert()
bt <- capture.output(traceback(5))
warnings()
Expand All @@ -63,7 +64,7 @@ irace.assert <- function(exp, eval_after = NULL)
msg_after <- eval.parent(capture.output(eval_after))
msg <- paste0(msg, "\n", paste0(msg_after, collapse="\n"))
}
irace.internal.error(msg)
irace_internal_error(msg)
invisible()
}

Expand Down Expand Up @@ -225,7 +226,7 @@ test.type.order.str <- function(test.type)
t.none =, # Fall-throught
t.holm =, # Fall-throught
t.bonferroni = "mean value",
irace.internal.error ("test.type.order.str() Invalid value '",
irace_internal_error ("test.type.order.str() Invalid value '",
test.type, "' of test.type"))


Expand Down

0 comments on commit 7c8cd1b

Please sign in to comment.