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]