From c8e81d46663c01ac19aca814410429b7bc818f10 Mon Sep 17 00:00:00 2001 From: "alex.hill@gmail.com" Date: Wed, 21 Aug 2024 13:28:28 +0100 Subject: [PATCH] lint --- R/api.R | 12 +++++++----- R/utils.R | 12 ++++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/R/api.R b/R/api.R index 6e06e8c..63c186b 100644 --- a/R/api.R +++ b/R/api.R @@ -99,18 +99,20 @@ target_get_trace <- function(name, filter_var <- filter_def[[1]][1] filter_level <- filter_def[[1]][2] if (!(filter_var %in% cols)) { - porcelain::porcelain_stop(paste("Column", filter_var, "not found in data"), + porcelain::porcelain_stop(paste("Column", + filter_var, + "not found in data"), code = "BAD_REQUEST", status_code = 400L) } - dat <- dat[dat[filter_var] == filter_level,] + dat <- dat[dat[filter_var] == filter_level, ] } - dat <- dat[dat["biomarker"] == biomarker,] + dat <- dat[dat["biomarker"] == biomarker, ] if (length(disaggregate) > 0) { logger::log_info(paste("Disaggregating by variables:", disaggregate)) groups <- split(dat, eval(parse(text = paste("~", disaggregate)))) nms <- names(groups) return(lapply(seq_along(groups), function(i) { - model <- withWarnings(model_out(groups[[i]], xcol)) + model <- with_warnings(model_out(groups[[i]], xcol)) list(name = jsonlite::unbox(nms[[i]]), model = model$output, raw = data_out(groups[[i]], xcol), @@ -118,7 +120,7 @@ target_get_trace <- function(name, })) } else { logger::log_info("Returning single trace") - model <- withWarnings(model_out(dat, xcol)) + model <- with_warnings(model_out(dat, xcol)) return(list(list(name = jsonlite::unbox("all"), model = model$output, raw = data_out(dat, xcol), diff --git a/R/utils.R b/R/utils.R index d28adf5..338b91d 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,10 +1,10 @@ -withWarnings <- function(expr) { - myWarnings <- NULL - wHandler <- function(w) { - myWarnings <<- c(myWarnings, list(w)) +with_warnings <- function(expr) { + my_warnings <- NULL + w_handler <- function(w) { + my_warnings <<- c(my_warnings, list(w)) invokeRestart("muffleWarning") } - val <- withCallingHandlers(expr, warning = wHandler) - list(output = val, warnings = lapply(myWarnings, + val <- withCallingHandlers(expr, warning = w_handler) + list(output = val, warnings = lapply(my_warnings, function(w) jsonlite::unbox(w$message))) }