From 8579a3e75440c5fe79b1786ca0de2861cdaccfeb Mon Sep 17 00:00:00 2001 From: Adrian Steffan Date: Tue, 27 Aug 2024 08:44:18 -0700 Subject: [PATCH] Fix for NULL strings introduced by jsonlite::fromJSON --- DESCRIPTION | 2 +- R/peekbankr.R | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 348729e..8d861b3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: peekbankr Type: Package Title: Accessing the Peekbank Database -Version: 0.1.1.9009 +Version: 0.1.1.9010 Authors@R: c( person("Mika", "Braginsky", email = "mika.br@gmail.com", role = c("aut", "cre")), person("Kyle", "MacDonald", email = "kylem412@gmail.com", role = "aut"), diff --git a/R/peekbankr.R b/R/peekbankr.R index 4999f09..ca08798 100644 --- a/R/peekbankr.R +++ b/R/peekbankr.R @@ -552,6 +552,21 @@ unpack_aux_data <- function(df) { aux_cols <- lapply(col_names, \(col_name) { sapply(aux_list, \(aux) { + # cursed way to make sure that there are no "NULL" strings left over + # from weird jsonlite::fromJSON behavior, + # check https://github.com/jeroen/jsonlite/issues/70 to see if there has been a fix by now + if(length(aux) == 1 && + (is.na(aux) || + is.null(aux[col_name]) || + aux[col_name] == "NULL" + ) || ( + all(is.na(aux)) || + all(is.null(aux[col_name]) ) || + all(aux[col_name] == "NULL") + ) + ){ + return(NA) + } aux[col_name] }) }) |>