Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
hillalex committed Aug 21, 2024
1 parent 69292a8 commit c8e81d4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
12 changes: 7 additions & 5 deletions R/api.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,28 @@ 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),
warnings = model$warnings)
}))
} 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),
Expand Down
12 changes: 6 additions & 6 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -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)))
}

0 comments on commit c8e81d4

Please sign in to comment.