From bd01e018f77d4aa58d6d4a017f7247923d228078 Mon Sep 17 00:00:00 2001 From: dimalvovs Date: Wed, 13 Mar 2024 15:29:09 -0400 Subject: [PATCH] address case of character vector passed as param --- R/utils.R | 1 + tests/testthat/test-utils.R | 1 + 2 files changed, 2 insertions(+) diff --git a/R/utils.R b/R/utils.R index 6c0d4cef..6edab664 100644 --- a/R/utils.R +++ b/R/utils.R @@ -328,6 +328,7 @@ check_arg <- function(arg, allow_class = NULL, allow_len = NULL, #' @return obj Object itself in case its not a character read_if_char <- function(obj) { if (is(obj, "character")) { + check_arg(obj, allow_class = "character", allow_len = 1) obj <- read.csv(obj, stringsAsFactors = FALSE) } return(obj) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index b96dcd17..1eb2e8c1 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -16,6 +16,7 @@ test_that("bool conversion function works",{ test_that("read if char tries to read a file", { expect_error(read_if_char("./file_that_not_exists.csv", "cannot open the connection")) + expect_error(read_if_char(c('a', 'b')), "Length of obj must be one of: 1") }) test_that("mandatory field absence yields error, presence does not", {