Skip to content

Commit

Permalink
added check for type of result in data wrangling tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Konrad1991 committed Nov 7, 2024
1 parent ff4340e commit 838672b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion bs/R/OperationsModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,14 @@ OperationEditorServer <- function(id, data) {
list2env(r_vals$intermediate_vars, envir = eval_env)
list2env(r_vals$df, envir = eval_env) # NOTE: this adds each column as own variable
new <- eval(parse(text = code), envir = eval_env)
check_type_res(new)
})
if (inherits(e, "try-error")) {
err <- conditionMessage(attr(e, "condition"))
showNotification(err, type = "error")
} else {
r_vals$intermediate_vars[[var_name]] <- new
}
r_vals$intermediate_vars[[var_name]] <- new
})

# Run operation and append to df
Expand Down Expand Up @@ -453,6 +455,7 @@ OperationEditorServer <- function(id, data) {
list2env(r_vals$intermediate_vars, envir = eval_env)
list2env(r_vals$df, envir = eval_env) # NOTE: this adds each column as own variable
new <- eval(parse(text = code), envir = eval_env)
check_type_res(new)
r_vals$df[, new_col] <- new
})
if (inherits(e, "try-error")) {
Expand Down
8 changes: 8 additions & 0 deletions bs/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,11 @@ check_axis_limits <- function(col, min, max) {
return()
}
}

# check that result is only of allowed type
check_type_res <- function(res) {
allowed <- c("numeric", "integer", "logical", "data.frame")
if (!(class(res) %in% allowed)) {
stop(paste0("Found result with unallowed type: ", class(res)))
}
}

0 comments on commit 838672b

Please sign in to comment.