From ee491673fa42d9638dd526b7f0060bc841795626 Mon Sep 17 00:00:00 2001 From: Norwin Roosen Date: Sat, 20 Oct 2018 11:32:22 +0200 Subject: [PATCH] fix issue with missing lastMeasurement --- R/00utils.R | 9 +++++++++ R/box.R | 1 + 2 files changed, 10 insertions(+) diff --git a/R/00utils.R b/R/00utils.R index 8099613..1ce9673 100644 --- a/R/00utils.R +++ b/R/00utils.R @@ -24,3 +24,12 @@ is_non_interactive = function () { ff = sapply(sys.calls(), function(f) as.character(f[1])) any(ff %in% c('knit2html', 'render')) || !interactive() } + +#' custom recursive lapply with better handling of NULL values +#' from https://stackoverflow.com/a/38950304 +recursive_lapply = function(x, fn) { + if (is.list(x)) + lapply(x, recursive_lapply, fn) + else + fn(x) +} diff --git a/R/box.R b/R/box.R index a140b02..7a5031f 100644 --- a/R/box.R +++ b/R/box.R @@ -157,6 +157,7 @@ parse_senseboxdata = function (boxdata) { # create a dataframe of sensors thebox$sensors = sensors %>% + recursive_lapply(function (x) if (is.null(x)) NA else x) %>% # replace NULLs with NA lapply(as.data.frame, stringsAsFactors = F) %>% dplyr::bind_rows(.) %>% dplyr::select(phenomenon = title, id = X_id, unit, sensor = sensorType) %>%