nptscot / osmactive

Extract active travel infrastructure from OSM
https://nptscot.github.io/osmactive/
Other
7 stars 0 forks source link

Refine functions #13

Closed atumscott closed 3 months ago

atumscott commented 3 months ago
Robinlovelace commented 3 months ago

Great to see this Joey, can you try running

devtools::check()

To see if it passes the tests, seems the automated checks on GitHub workflow is failing.

joeytalbot commented 3 months ago

There is one error. I think the field segregated needs to be defined

Robinlovelace commented 3 months ago

I had a quick look and it's because segregated wasn't in the example dataset. This can be seen in the outputs of check():

``` devtools::check() ══ Documenting ═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════ ℹ Updating osmactive documentation ℹ Loading osmactive ══ Building ════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════ Setting env vars: • CFLAGS : -Wall -pedantic -fdiagnostics-color=always • CXXFLAGS : -Wall -pedantic -fdiagnostics-color=always • CXX11FLAGS: -Wall -pedantic -fdiagnostics-color=always • CXX14FLAGS: -Wall -pedantic -fdiagnostics-color=always • CXX17FLAGS: -Wall -pedantic -fdiagnostics-color=always • CXX20FLAGS: -Wall -pedantic -fdiagnostics-color=always ── R CMD build ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── ✔ checking for file ‘/home/robin/github/nptscot/osmactive/DESCRIPTION’ ... ─ preparing ‘osmactive’: (400ms) ✔ checking DESCRIPTION meta-information ... ─ checking for LF line-endings in source and make files and shell scripts ─ checking for empty or unneeded directories Removed empty directory ‘osmactive/vignettes’ ─ building ‘osmactive_0.0.0.9000.tar.gz’ ══ Checking ════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════ Setting env vars: • _R_CHECK_CRAN_INCOMING_USE_ASPELL_ : TRUE • _R_CHECK_CRAN_INCOMING_REMOTE_ : FALSE • _R_CHECK_CRAN_INCOMING_ : FALSE • _R_CHECK_FORCE_SUGGESTS_ : FALSE • _R_CHECK_PACKAGES_USED_IGNORE_UNUSED_IMPORTS_: FALSE • NOT_CRAN : true ── R CMD check ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── ─ using log directory ‘/tmp/RtmpOjWPQx/fileecad2a22ba1c/osmactive.Rcheck’ ─ using R version 4.3.3 (2024-02-29) ─ using platform: x86_64-pc-linux-gnu (64-bit) ─ R was compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 GNU Fortran (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 ─ running under: Ubuntu 22.04.4 LTS ─ using session charset: UTF-8 ─ using options ‘--no-manual --as-cran’ (1.6s) ✔ checking for file ‘osmactive/DESCRIPTION’ ... ─ this is package ‘osmactive’ version ‘0.0.0.9000’ ─ package encoding: UTF-8 ✔ checking package namespace information ✔ checking package dependencies (654ms) ✔ checking if this is a source package ... ✔ checking if there is a namespace ✔ checking for executable files ... ✔ checking for hidden files and directories ... ✔ checking for portable file names ✔ checking for sufficient/correct file permissions ✔ checking serialization versions ... ✔ checking whether package ‘osmactive’ can be installed (639ms) ✔ checking installed package size ... ✔ checking package directory ✔ checking for future file timestamps (725ms) ✔ checking DESCRIPTION meta-information ... N checking top-level files ... Non-standard files/directories found at top level: ‘README.html’ ‘classify_cycle_infrastructure_dublin.html’ ‘classify_cycle_infrastructure_leeds.html’ ‘classify_cycleways_leeds.html’ ‘cycle_net_edinburgh.html’ ‘cycle_network_classified_edinburgh.html’ ‘leeds.html’ ‘lisbon_municipalities.gpkg’ ‘segregation_levels_edinburgh.html’ ‘segregation_levels_leeds.html’ ‘segregation_levels_lisbon.html’ ✔ checking for left-over files ✔ checking index information ✔ checking package subdirectories ... ✔ checking R files for non-ASCII characters ... ✔ checking R files for syntax errors ... ✔ checking whether the package can be loaded ... ✔ checking whether the package can be loaded with stated dependencies ... ✔ checking whether the package can be unloaded cleanly ... ✔ checking whether the namespace can be loaded with stated dependencies ... ✔ checking whether the namespace can be unloaded cleanly ... ✔ checking loading without being on the library search path ... ✔ checking dependencies in R code (2.9s) ✔ checking S3 generic/method consistency ... ✔ checking replacement functions ... ✔ checking foreign function calls ... N checking R code for possible problems (1.2s) classify_cycle_infrastructure_scotland: no visible binding for global variable ‘cycle_segregation’ get_cycling_network: no visible binding for global variable ‘bicycle’ get_travel_network: no visible binding for global variable ‘service’ plot_osm_tmap: no visible global function definition for ‘packageVersion’ plot_osm_tmap: no visible global function definition for ‘desc’ plot_osm_tmap: no visible binding for global variable ‘cycle_segregation’ Undefined global functions or variables: bicycle cycle_segregation desc packageVersion service Consider adding importFrom("utils", "packageVersion") to your NAMESPACE file. ✔ checking Rd files ... ✔ checking Rd metadata ... ✔ checking Rd line widths ... ✔ checking Rd cross-references ... ✔ checking for missing documentation entries ... ✔ checking for code/documentation mismatches ... ✔ checking Rd \usage sections ... ✔ checking Rd contents ... ✔ checking for unstated dependencies in examples ... ✔ checking contents of ‘data’ directory ... ✔ checking data for non-ASCII characters ... ✔ checking LazyData ✔ checking data for ASCII and uncompressed saves ... E checking examples (4.8s) Running examples in ‘osmactive-Ex.R’ failed The error most likely occurred in: > base::assign(".ptime", proc.time(), pos = "CheckExEnv") > ### Name: classify_cycle_infrastructure > ### Title: Segregation levels > ### Aliases: classify_cycle_infrastructure > > ### ** Examples > > library(tmap) Attaching package: ‘tmap’ The following object is masked from ‘package:datasets’: rivers > tmap_mode("plot") tmap mode set to 'plot' > osm = osm_edinburgh > cycle_network = get_cycling_network(osm) > driving_network = get_driving_network(osm) > netd = distance_to_road(cycle_network, driving_network) > netc = classify_cycle_infrastructure(netd) Error in `stopifnot()`: ℹ In argument: `detailed_segregation = dplyr::case_when(...)`. Caused by error in `dplyr::case_when()`: ! Failed to evaluate the left-hand side of formula 4. Caused by error: ! object 'segregated' not found Backtrace: ▆ 1. ├─osmactive::classify_cycle_infrastructure(netd) 2. │ └─osmactive:::classify_cycle_infrastructure_scotland(osm, min_distance) 3. │ ├─dplyr::mutate(...) 4. │ ├─dplyr::mutate(...) 5. │ ├─dplyr::mutate(...) 6. │ ├─tidyr::unite(...) 7. │ ├─dplyr::mutate(...) 8. │ ├─dplyr::mutate(...) 9. │ ├─dplyr::mutate(...) 10. │ ├─sf:::mutate.sf(...) 11. │ │ └─sf:::.re_sf(NextMethod(), sf_column_name = sf_column_name, agr) 12. │ │ └─base::stopifnot(...) 13. │ ├─base::NextMethod() 14. │ └─dplyr:::mutate.data.frame(...) 15. │ └─dplyr:::mutate_cols(.data, dplyr_quosures(...), by) 16. │ ├─base::withCallingHandlers(...) 17. │ └─dplyr:::mutate_col(dots[[i]], data, mask, new_columns) 18. │ └─mask$eval_all_mutate(quo) 19. │ └─dplyr (local) eval() 20. ├─dplyr::case_when(...) 21. │ └─dplyr:::case_formula_evaluate(...) 22. │ ├─base::withCallingHandlers(...) 23. │ └─rlang::eval_tidy(pair$lhs, env = default_env) 24. └─base::.handleSimpleError(...) 25. └─dplyr (local) h(simpleError(msg, call)) 26. └─rlang::abort(message, parent = cnd, call = error_call) Execution halted ✔ checking for non-standard things in the check directory ✔ checking for detritus in the temp directory See ‘/tmp/RtmpOjWPQx/fileecad2a22ba1c/osmactive.Rcheck/00check.log’ for details. ── R CMD check results ─────────────────────────────────────────────────────────────────────────────────────────── osmactive 0.0.0.9000 ──── Duration: 16.5s ❯ checking examples ... ERROR Running examples in ‘osmactive-Ex.R’ failed The error most likely occurred in: > base::assign(".ptime", proc.time(), pos = "CheckExEnv") > ### Name: classify_cycle_infrastructure > ### Title: Segregation levels > ### Aliases: classify_cycle_infrastructure > > ### ** Examples > > library(tmap) Attaching package: ‘tmap’ The following object is masked from ‘package:datasets’: rivers > tmap_mode("plot") tmap mode set to 'plot' > osm = osm_edinburgh > cycle_network = get_cycling_network(osm) > driving_network = get_driving_network(osm) > netd = distance_to_road(cycle_network, driving_network) > netc = classify_cycle_infrastructure(netd) Error in `stopifnot()`: ℹ In argument: `detailed_segregation = dplyr::case_when(...)`. Caused by error in `dplyr::case_when()`: ! Failed to evaluate the left-hand side of formula 4. Caused by error: ! object 'segregated' not found Backtrace: ▆ 1. ├─osmactive::classify_cycle_infrastructure(netd) 2. │ └─osmactive:::classify_cycle_infrastructure_scotland(osm, min_distance) 3. │ ├─dplyr::mutate(...) 4. │ ├─dplyr::mutate(...) 5. │ ├─dplyr::mutate(...) 6. │ ├─tidyr::unite(...) 7. │ ├─dplyr::mutate(...) 8. │ ├─dplyr::mutate(...) 9. │ ├─dplyr::mutate(...) 10. │ ├─sf:::mutate.sf(...) 11. │ │ └─sf:::.re_sf(NextMethod(), sf_column_name = sf_column_name, agr) 12. │ │ └─base::stopifnot(...) 13. │ ├─base::NextMethod() 14. │ └─dplyr:::mutate.data.frame(...) 15. │ └─dplyr:::mutate_cols(.data, dplyr_quosures(...), by) 16. │ ├─base::withCallingHandlers(...) 17. │ └─dplyr:::mutate_col(dots[[i]], data, mask, new_columns) 18. │ └─mask$eval_all_mutate(quo) 19. │ └─dplyr (local) eval() 20. ├─dplyr::case_when(...) 21. │ └─dplyr:::case_formula_evaluate(...) 22. │ ├─base::withCallingHandlers(...) 23. │ └─rlang::eval_tidy(pair$lhs, env = default_env) 24. └─base::.handleSimpleError(...) 25. └─dplyr (local) h(simpleError(msg, call)) 26. └─rlang::abort(message, parent = cnd, call = error_call) Execution halted ❯ checking top-level files ... NOTE Non-standard files/directories found at top level: ‘README.html’ ‘classify_cycle_infrastructure_dublin.html’ ‘classify_cycle_infrastructure_leeds.html’ ‘classify_cycleways_leeds.html’ ‘cycle_net_edinburgh.html’ ‘cycle_network_classified_edinburgh.html’ ‘leeds.html’ ‘lisbon_municipalities.gpkg’ ‘segregation_levels_edinburgh.html’ ‘segregation_levels_leeds.html’ ‘segregation_levels_lisbon.html’ ❯ checking R code for possible problems ... NOTE classify_cycle_infrastructure_scotland: no visible binding for global variable ‘cycle_segregation’ get_cycling_network: no visible binding for global variable ‘bicycle’ get_travel_network: no visible binding for global variable ‘service’ plot_osm_tmap: no visible global function definition for ‘packageVersion’ plot_osm_tmap: no visible global function definition for ‘desc’ plot_osm_tmap: no visible binding for global variable ‘cycle_segregation’ Undefined global functions or variables: bicycle cycle_segregation desc packageVersion service Consider adding importFrom("utils", "packageVersion") to your NAMESPACE file. 1 error ✖ | 0 warnings ✔ | 2 notes ✖ ```
Robinlovelace commented 3 months ago

Suggested solution: add the segretated column back into the dataset.

Robinlovelace commented 3 months ago

Heads-up @joeytalbot #15 should fix this, please review and merge. See #14 for diagnosis, good to see segregated keys in our example dataset.

Robinlovelace commented 3 months ago

Have done some tests and cannot see any differences in the results:

waldo::compare(as.character(cycle_net$cycle_segregation), cycle_net_new$cycle_segregation)
✔ No differences

Reproducible example:

leeds_6km = leeds_zb |>
  filter(circle_id <= 3) |>
  sf::st_union()
osm = get_travel_network("Leeds", boundary = leeds_6km, boundary_type = "clipsrc")
cycle_net = get_cycling_network(osm)
drive_net = get_driving_network_major(osm)
cycle_net = distance_to_road(cycle_net, drive_net)
# git checkout main
devtools::load_all()
cycle_net = classify_cycle_infrastructure(cycle_net)
m = plot_osm_tmap(cycle_net)
tmap_save(m, "classify_cycle_infrastructure_leeds_new.html")
system("diff classify_cycle_infrastructure_leeds.html classify_cycle_infrastructure_leeds_new.html")
browseURL("classify_cycle_infrastructure_leeds.html")

# Re-run after checking out classification branch with git checkout classification
# git checkout classification
devtools::load_all()
cycle_net_new = classify_cycle_infrastructure(cycle_net)
# Compare old and new
waldo::compare(as.character(cycle_net$cycle_segregation), cycle_net_new$cycle_segregation)