Skip to content

Commit

Permalink
Update default behavior of 'Conf' objects
Browse files Browse the repository at this point in the history
In recent scenarios and in perspective of up-coming changes, the default
behavior of 'Conf' objects upon initialization and update:

1) The default values are *not* automatically checked against the
allowed values anymore. This is mainly disabled to avoid confusion of
users. The constructor of the class 'Conf' is adapted accordingly.
2) When updating a configuration value, the program execution is now
stopped (using 'stop') on failure. Previously, the respective update has
been ignored while issuing a warning. This change helps preventing
confusion and analysis errors early in an analysis script. Accordingly,
the parameter 'stop.on.error' to all update methods is removed.

Furthermore, the code is streamlined, such that the super-constructor is
called from both subclasses 'NetworkConf' and 'ProjectConf'. Some log
statements are added/adjusted, too.

Signed-off-by: Claus Hunsen <[email protected]>
  • Loading branch information
clhunsen authored and fehnkera committed Sep 23, 2020
1 parent bb0ed5b commit bdfe265
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions util-conf.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Conf = R6::R6Class("Conf",
return(self$get.value(att))
})
names(current.values) = names(private$attributes)
self$update.values(current.values, stop.on.error = TRUE)
self$update.values(current.values)
},

#' Check whether the given 'value' is the correct datatype
Expand Down Expand Up @@ -125,8 +125,8 @@ Conf = R6::R6Class("Conf",

#' The constructor, automatically checking the default values.
initialize = function() {
## FIXME do we need this?
private$check.values()
# ## check the default values for validity
# private$check.values()
},

## * * printing ----------------------------------------------------
Expand Down Expand Up @@ -166,8 +166,7 @@ Conf = R6::R6Class("Conf",
#'
#' @param entry the entry name for the value
#' @param value the new value
#' @param error call stop() on an error? [default: FALSE]
update.value = function(entry, value, stop.on.error = FALSE) {
update.value = function(entry, value) {
## construct list for updating
updating = list(value)
names(updating) = entry
Expand All @@ -179,10 +178,9 @@ Conf = R6::R6Class("Conf",
#' 'updated.values' list.
#'
#' @param updated.values the new values for the attributes to be updated
#' @param error call stop() on an error? [default: FALSE]
update.values = function(updated.values = list(), stop.on.error = FALSE) {
update.values = function(updated.values = list()) {
## determine the function executed on an error
error.function = ifelse(stop.on.error, stop, logging::logwarn)
error.function = stop

## check values to update
names.to.update = c()
Expand Down Expand Up @@ -219,9 +217,7 @@ Conf = R6::R6Class("Conf",

} else {
message = paste0(
"Updating network-configuration attribute '%s' failed.",
if (!stop.on.error) " The failure is ignored!\n",
# "Current value: %s\n",
"Updating network-configuration attribute '%s' failed.\n",
"Allowed values (%s of type '%s'): %s\n",
"Given value (of type '%s'): %s"
)
Expand Down Expand Up @@ -476,6 +472,10 @@ ProjectConf = R6::R6Class("ProjectConf", inherit = Conf,
#' and \code{featureexpression}) [default: "feature"]
initialize = function(data, selection.process, casestudy, artifact = c("feature", "file",
"function", "featureexpression")) {

logging::loginfo("Construct project configuration: starting.")

## call super constructor
super$initialize()

## verify arguments using match.arg
Expand All @@ -486,8 +486,6 @@ ProjectConf = R6::R6Class("ProjectConf", inherit = Conf,
private$casestudy = verify.argument.for.parameter(casestudy, "character", class(self)[1])
private$artifact = verify.argument.for.parameter(artifact, "character", class(self)[1])

logging::loginfo("Construct project configuration: starting.")

## convert artifact to tagging
tagging = ARTIFACT.TO.TAGGING[[ artifact ]]
if (is.null(tagging)) {
Expand Down Expand Up @@ -762,16 +760,20 @@ NetworkConf = R6::R6Class("NetworkConf", inherit = Conf,

#' The constructor, automatically checking the default values.
initialize = function() {
# private$check.values()
logging::loginfo("Construct network configuration: starting.")

## call super constructor
super$initialize()

logging::loginfo("Construct network configuration: finished.")
},

#' Update the attributes of the class with the new values given in the
#' 'updated.values' list.
#'
#' @param updated.values the new values for the attributes to be updated
#' @param error call stop() on an error? [default: FALSE]
update.values = function(updated.values = list(), stop.on.error = FALSE) {
super$update.values(updated.values = updated.values, stop.on.error = stop.on.error)
update.values = function(updated.values = list()) {
super$update.values(updated.values = updated.values)

## 1) "date" and "artifact.type" always as edge attribute
name = "edge.attributes"
Expand Down

0 comments on commit bdfe265

Please sign in to comment.