From 8adcd8ae2905035e3215baeb10f0d464d01ea8cf Mon Sep 17 00:00:00 2001 From: dwachsmuth Date: Fri, 23 Feb 2024 07:25:41 -0500 Subject: [PATCH] Bug fix to strr_ghost for edge cases with few rows --- R/strr_ghost.R | 4 ++++ R/strr_ghost_helpers.R | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/R/strr_ghost.R b/R/strr_ghost.R index ebbfb3a..b72d9d2 100644 --- a/R/strr_ghost.R +++ b/R/strr_ghost.R @@ -276,6 +276,10 @@ strr_ghost <- function( MoreArgs = list(min_listings = min_listings), SIMPLIFY = FALSE)] + # Error handling for one-row case where no clusters were identified + if (nrow(property) == 1 && is.null(property$data)) + return(ghost_empty(crs_property)) + # Get rid of rows without valid tables property <- property[!sapply(data, is.null)] diff --git a/R/strr_ghost_helpers.R b/R/strr_ghost_helpers.R index a513122..fe84c06 100644 --- a/R/strr_ghost_helpers.R +++ b/R/strr_ghost_helpers.R @@ -31,7 +31,9 @@ ghost_date_range <- function(data, dates, min_listings) { start = dates[-length(dates)], end = dates[-1] - 1) date_table[, PID := mapply(\(start, end) sort(data[ - created <= start & scraped >= end]$property_ID), start, end)] + created <= start & scraped >= end]$property_ID), start, end, + # SIMPLIFY = FALSE in case of one-row output + SIMPLIFY = FALSE)] date_table <- date_table[lengths(PID) >= min_listings]