Skip to content

Commit

Permalink
address case of character vector passed as param
Browse files Browse the repository at this point in the history
  • Loading branch information
dimalvovs committed Mar 13, 2024
1 parent 5fd637f commit bd01e01
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down

0 comments on commit bd01e01

Please sign in to comment.