Created
February 3, 2019 22:08
-
-
Save brry/7728b9b2d35afad7f1fc5978c3315009 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if(!requireNamespace("devtools")) install.packages("devtools") | |
| if(!requireNamespace("osmplotr")) install.packages("osmplotr") | |
| dir.create("sfsubsettest/R", recursive=TRUE) | |
| setwd("sfsubsettest") | |
| cat("Package: sfsubsettest | |
| Title: Check sf Subset | |
| Version: 0.0.1 | |
| Author: Berry Boessenkool | |
| Maintainer: Berry Boessenkool <[email protected]> | |
| License: GPL-2 | |
| Description: Check sf Subset. | |
| Imports: osmplotr\n", file="DESCRIPTION") | |
| cat(paste("#' dummy function\n#' @param map map\n#' @param obj obj", | |
| "#' @importFrom osmplotr add_osm_objects\n#' @export", | |
| "dummy <- function(map,obj)\n{", | |
| " add_osm_objects(map, obj[1:10,], col='green')\n}", sep="\n"), | |
| file="R/dummy.R") | |
| devtools::document() | |
| devtools::install() | |
| library(sfsubsettest) | |
| library(osmplotr) | |
| bbox <- get_bbox(c(12.5, 53.1, 12.6, 53.2)) | |
| dat_F <- extract_osm_objects(key="landuse", bbox=bbox, quiet=TRUE, value="forest") | |
| map <- osm_basemap(bbox=bbox, bg='gray95') | |
| map <- dummy(map, dat_F) # class(obj$geometry) problem | |
| class(dat_F$geometry) # sfc | |
| class(dat_F[1:10,]$geometry) # list | |
| # now change "[" to sf:::"[.sf" | |
| cat(paste("#' dummy function\n#' @param map map\n#' @param obj obj", | |
| "#' @importFrom osmplotr add_osm_objects\n#' @export", | |
| "dummy <- function(map,obj)\n{", | |
| " add_osm_objects(map, sf:::'[.sf'(obj, 1:10, 1:ncol(obj)), col='green')\n}", sep="\n"), | |
| file="R/dummy.R") | |
| devtools::document() | |
| devtools::install() | |
| library(sfsubsettest) | |
| map <- dummy(map, dat_F) # now works fine | |
| map | |
| remove.packages("sfsubsettest") | |
| setwd("..") | |
| unlink("sfsubsettest", recursive=TRUE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See comment here - this will always fail without
sfbeing explicitly loaded because (1)osmplotrdoes not, nor will, depend onsf, that's an uneccessarily "heavy" dependency; and (2) sub-setting is arguably ansfoperation that lies beyond the remit ofosmplotr, and so it is fair to expectsfto be loaded for that operation. There is unfortunately no place withinosmplotrat which a suitably useful message might be issued regarding the necessity of loadingsffor such operations, because the objects returned byextract_osm_objects()are intended to be indistinguishable from anysfobjects generated with that package.