cynthiahqy / conformr-xmap-project

R Package for harmonising data of different classifications or aggregations into a single dataset
MIT License
7 stars 1 forks source link

Refactor `abort` functions to take `stop` flag, and message relevant arguments #120

Closed cynthiahqy closed 1 year ago

cynthiahqy commented 1 year ago

abort_<condition> functions should have a single purpose -- to return an error message, and the calculation of the boolean flag should be separate i.e.

abort_condition <- function(text_arg){
  cli::cli_abort("message with {text_arg}")
stop <- TRUE
if (stop) {
  abort_condition(text_arg)
}
cynthiahqy commented 1 year ago

Can get a bit convoluted though e.g. for abort_weights_col_type

is_df_col_type <- function(df, col_name,
                           col_type = c("numeric")){
  switch(col_type,
         numeric = is.numeric(df[[col_name]]))

}

abort_df_col_type <- function(col_name, col_type){
  cli::cli_abort(
      message = "The column `{col_name}` should be of type {col_type}",
      class = "abort_col_type"
    )
}
cynthiahqy commented 1 year ago

Use format_message() instead as shown in https://github.com/cynthiahqy/conformr-xmap-project/pull/121/commits/14c0914d4133231473883df2ddd45bd6d443c728