Skip to content

Commit

Permalink
Defensive changes
Browse files Browse the repository at this point in the history
Check for type id columns in osmchange_*()
Avoid simplification of 1 col data frames
  • Loading branch information
jmaspons committed Aug 10, 2024
1 parent 87d56c6 commit 9d92113
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: osmapiR
Title: 'OpenStreetMap' API
Version: 0.1.0.9019
Version: 0.1.0.9020
Authors@R: c(
person("Joan", "Maspons", , "[email protected]", role = c("aut", "cre", "cph"),
comment = c(ORCID = "0000-0003-2286-8727")),
Expand Down
3 changes: 3 additions & 0 deletions R/osmchange.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ osmchange_modify <- function(x, tag_keys, members = FALSE, lat_lon = FALSE, form
if (inherits(x, "tags_wide")) {
x <- tags_wide2list(x)
}
stopifnot(c("type", "id") %in% colnames(x))

if (missing(tag_keys)) { # Update all tags
tags_upd <- x$tags
Expand Down Expand Up @@ -162,6 +163,8 @@ osmchange_delete <- function(x, delete_if_unused = FALSE, format = c("R", "osc",
if (inherits(x, "tags_wide")) {
x <- tags_wide2list(x)
}
stopifnot(c("type", "id") %in% colnames(x))

x_type <- split(x, x$type)
osmchange <- lapply(x_type, function(y) osm_fetch_objects(osm_type = unique(y$type), osm_ids = y$id))
osmchange <- do.call(rbind, osmchange[c("relation", "way", "node")]) # sort to avoid deleting members of existing objs
Expand Down
4 changes: 2 additions & 2 deletions R/tags_list-wide.r
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ tags_list2wide <- function(x) {
dimnames = list(NULL, cols)
)

out <- x[, setdiff(names(x), "tags")]
out <- x[, setdiff(names(x), "tags"), drop = FALSE]
if (inherits(x, "osmapi_objects")) {
names(out) <- gsub("^(type|id)$", "osm_\\1", names(out))
}
Expand Down Expand Up @@ -98,7 +98,7 @@ tags_wide2list <- function(x) {
return(out)
}, simplify = FALSE)

out <- x[, -keys]
out <- x[, -keys, drop = FALSE]
out$tags <- tags_list

if (inherits(x, "osmapi_objects")) {
Expand Down
4 changes: 2 additions & 2 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"codeRepository": "https://github.com/ropensci/osmapiR",
"issueTracker": "https://github.com/ropensci/osmapiR/issues",
"license": "https://spdx.org/licenses/GPL-3.0",
"version": "0.1.0.9019",
"version": "0.1.0.9020",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down Expand Up @@ -180,7 +180,7 @@
"name": "osmapiR: OpenStreetMap API",
"identifier": "10.32614/CRAN.package.osmapiR",
"url": "https://docs.ropensci.org/osmapiR/",
"description": "R package version 0.1.0.9019 \nhttps://github.com/ropensci/osmapiR",
"description": "R package version 0.1.0.9020 \nhttps://github.com/ropensci/osmapiR",
"@id": "https://doi.org/10.32614/CRAN.package.osmapiR",
"sameAs": "https://doi.org/10.32614/CRAN.package.osmapiR"
}
Expand Down

0 comments on commit 9d92113

Please sign in to comment.