Skip to content

Commit

Permalink
Bug fix to strr_ghost for edge cases with few rows
Browse files Browse the repository at this point in the history
  • Loading branch information
dwachsmuth committed Feb 23, 2024
1 parent a17500c commit 8adcd8a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions R/strr_ghost.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down
4 changes: 3 additions & 1 deletion R/strr_ghost_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down

0 comments on commit 8adcd8a

Please sign in to comment.