Skip to content

Commit

Permalink
Adds a check to make sure a parameter exists to modify it
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwarkentin committed Jan 17, 2024
1 parent d63e1a2 commit e7aa274
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions R/R6ClassWorkset.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ OpenMppWorkset <-
#' @return Self, invisibly.
delete_params = function(names) {
private$.check_modifiable()
purrr::map(names, \(x) private$.check_param_exists(x, rlang::caller_env(3)))
purrr::walk(
.x = names,
.f = \(name) {
Expand Down Expand Up @@ -175,6 +176,8 @@ OpenMppWorkset <-
#' @return Self, invisibly.
set_param = function(name, data) {
private$.check_modifiable()
private$.check_param_exists(name)

old <- self$get_param(name)

is_compatible(data, old)
Expand Down Expand Up @@ -316,6 +319,14 @@ OpenMppWorkset <-
call = call
)
}
},
.check_param_exists = function(param, call = rlang::caller_env()) {
if (!param %in% private$.params) {
rlang::abort(
message = 'Cannot modify a parameters that does not exit.',
call = call
)
}
}
),
active = list(
Expand Down

0 comments on commit e7aa274

Please sign in to comment.