From 9dd8e7bd0591511dbd1f8ff1959ee0c45bb00093 Mon Sep 17 00:00:00 2001 From: "alex.hill@gmail.com" Date: Thu, 26 Sep 2024 16:18:39 +0100 Subject: [PATCH] declare yaml package, add comment --- DESCRIPTION | 3 ++- R/api.R | 9 +-------- R/dataset-validation.R | 9 +++++++++ docker/Dockerfile | 3 ++- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ecb7262..f4a2aea 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,7 +27,8 @@ Imports: redoc, rlang, stringr, - tibble + tibble, + yaml Remotes: hillalex/porcelain@i39, Suggests: diff --git a/R/api.R b/R/api.R index 15da882..411f655 100644 --- a/R/api.R +++ b/R/api.R @@ -194,8 +194,6 @@ target_get_individual <- function(req, color = NULL, linetype = NULL, page = 1) { - .data <- value <- NULL - data <- read_dataset(req, name, scale) dat <- data$data xcol <- data$xcol @@ -244,6 +242,7 @@ get_paged_ids <- function(ids, current_page, page_length) { } get_aes <- function(color, linetype, xcol) { + .data <- value <- NULL if (is.null(color)) { if (is.null(linetype)) { aes <- ggplot2::aes(x = .data[[xcol]], y = value) @@ -347,12 +346,6 @@ apply_filter <- function(filter, dat, cols) { dat[dat[filter_var] == filter_level, ] } -bad_request_response <- function(msg) { - error <- list(error = "BAD_REQUEST", - detail = msg) - return(list(status = "failure", errors = list(error), data = NULL)) -} - get_or_create_session_id <- function(req) { if (is.null(req$session$id)) { logger::log_info("Creating new session id") diff --git a/R/dataset-validation.R b/R/dataset-validation.R index 07729b4..0eb0886 100644 --- a/R/dataset-validation.R +++ b/R/dataset-validation.R @@ -1,3 +1,12 @@ +# The POST /dataset endpoint isn't using Porcelain, so we can't use +# porcelain::porcelain_stop when something goes wrong. Instead we have +# to manually return failure responses with the desired error messages +bad_request_response <- function(msg) { + error <- list(error = "BAD_REQUEST", + detail = msg) + return(list(status = "failure", errors = list(error), data = NULL)) +} + invalid_file_type <- function(res) { res$status <- 400L msg <- "Invalid file type; please upload file of type text/csv." diff --git a/docker/Dockerfile b/docker/Dockerfile index 22da199..846af26 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -27,7 +27,8 @@ RUN install_packages --repo=https://mrc-ide.r-universe.dev \ remotes \ Rook \ stringr \ - tibble + tibble \ + yaml RUN Rscript -e "install.packages('remotes')" RUN Rscript -e 'remotes::install_github("hillalex/porcelain@i39")'