From ca1783528ac502e36a812185370eb465f1951daf Mon Sep 17 00:00:00 2001 From: wkmor1 Date: Tue, 23 Jul 2024 15:29:33 +0300 Subject: [PATCH] Use switch directly rather than casting NAs --- R/utils.R | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/R/utils.R b/R/utils.R index f8381516..2ee0168b 100644 --- a/R/utils.R +++ b/R/utils.R @@ -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_ + ) } @@ -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)