Skip to content

Commit

Permalink
mapply() -> .mapply() microoptimization
Browse files Browse the repository at this point in the history
Cases in osm_get_objects() require osm type names in list so not word it to change
  • Loading branch information
jmaspons committed Jun 13, 2024
1 parent 8401ef1 commit 1e67bb5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions R/osmapiR_objects.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,14 @@ validate_osmapi_objects <- function(x, commited = TRUE) {
lat = "character", lon = "character", members = "list", tags = "list"
)
sel_cols <- intersect(names(x), names(class_columns))
mapply(
.mapply(
function(col, cl, col_name) {
if (!inherits(col, cl)) {
stop("Column `", col_name, "` is not of `", cl, "` type.")
}
},
col = x[sel_cols], cl = class_columns[sel_cols], col_name = sel_cols
dots = list(col = x[sel_cols], cl = class_columns[sel_cols], col_name = sel_cols),
MoreArgs = NULL
)

ok_members <- vapply(
Expand Down
10 changes: 6 additions & 4 deletions R/osmapi_elements.R
Original file line number Diff line number Diff line change
Expand Up @@ -802,14 +802,16 @@ fetch_objects_batches <- function(osm_type, osm_ids, nchar_base, format, tags_in
ids_batch[length(ids_batch) + 1] <- sel_pos
}

obj_batch <- mapply(
obj_batch <- .mapply(
function(from, to) {
ids <- osm_ids[from:to]
osm_fetch_objects(osm_type = osm_type, osm_ids = ids, format = format) # version is already part of osm_ids
},
from = ids_batch[-length(ids_batch)],
to = c(ids_batch[-c(1, length(ids_batch))] - 1, length(osm_ids)),
SIMPLIFY = FALSE
dots = list(
from = ids_batch[-length(ids_batch)],
to = c(ids_batch[-c(1, length(ids_batch))] - 1, length(osm_ids))
),
MoreArgs = NULL
)

## Unite batches
Expand Down
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ minlon
mis
misformed
mispos
MoreArgs
mozilla
msg
municipis
Expand Down

0 comments on commit 1e67bb5

Please sign in to comment.