Skip to content

Commit

Permalink
Update od_disaggregate, fix #30
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinlovelace committed Apr 22, 2021
1 parent cfd9513 commit f75e934
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# od 0.2.1

* Updated `od_disaggregate()` so it's less likely to fail with unfathomable message (#30)

# od 0.2.0

* New `od_split()` function, a copy of `od_disaggregate()`
Expand Down
19 changes: 19 additions & 0 deletions R/aggregate.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,30 @@ od_disaggregate = function(od,
keep_ids = TRUE) {

if (is.null(subpoints)) {
message("Converting subzones to centroids")
suppressWarnings({
subpoints = sf::st_centroid(subzones)
})
}

# is the input data an sf object? tell the user and convert to df if so
if(is(object = od, class2 = "sf")) {
message("Input object is sf, attempting to convert to a data frame")
od = sf::st_drop_geometry(od)
}

# detect and deal with non numeric inputs
column_classes = sapply(X = od, FUN = function(x) class(x)[1])
column_classes_data = column_classes[3:length(column_classes)]
col_is_numeric = column_classes_data == "numeric"
all_numeric = all(col_is_numeric)
if(!all_numeric) {
names_od = names(od)[3:length(column_classes)]
names_readable = paste0(names_od[!col_is_numeric], collapse = ", ")
message("Attempting to remove non-numeric columns: ", names_readable)
od = od[setdiff(names(od), names_readable)]
}

o_in_zones = od[[1]] %in% z[[1]]
d_in_zones = od[[2]] %in% z[[1]]
if (!all(o_in_zones) || !all(d_in_zones)) {
Expand Down

0 comments on commit f75e934

Please sign in to comment.