Skip to content

type_fix in helper uses as(..., "factor") and doesnt convert logicals #98

@mboecker

Description

@mboecker

as(..., "factor") is not defined, but not caught in the loop.
also, this function can be used to automatically convert logicals, which are else somehow saved as strings.

my temporary fix in the rds branch:

type_fix = function(x, par.set) {
  # type conversion to make sure (Workaround for https://github.com/berndbischl/ParamHelpers/issues/203)
  par_types = getParamTypes(par.set, with.nr = TRUE, use.names = TRUE, df.cols = TRUE)
  df_types = vcapply(x, class)
  type_misses = df_types == "logical" & par_types[names(df_types)] != df_types
  if (any(type_misses)) {
    for (col in names(type_misses[type_misses])) {
      if(par_types[col] != "factor") {
        x[[col]] = as(x[[col]], par_types[col])
      }
    }
  }
  for (col in names(par_types)) {
    if (par_types[col] == "logical") {
      x[[col]] = as.logical(x[[col]])
    }
  }
  return(x)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions