Skip to content

Commit

Permalink
Use switch directly rather than casting NAs
Browse files Browse the repository at this point in the history
  • Loading branch information
wkmor1 committed Jul 23, 2024
1 parent dc06409 commit ca17835
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ get_el_recurse <- function(

if (is.null(obj) || identical(obj, "")) {

obj <- cast_to_type(NA, type)
obj <- switch(
type,
double = NA_real_,
integer = NA_integer_,
logical = NA,
NA_character_
)

}

Expand Down Expand Up @@ -50,7 +56,13 @@ get_el_recurse <- function(

null_elements <- vapply(next_obj, is.null, NA)

next_obj[null_elements] <- cast_to_type(NA, type)
next_obj[null_elements] <- switch(
type,
double = NA_real_,
integer = NA_integer_,
logical = NA,
NA_character_
)

next_obj <- unlist(next_obj, recursive = FALSE)

Expand Down

0 comments on commit ca17835

Please sign in to comment.