Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add minimal R package (#67) #68

Merged

Conversation

Robinlovelace
Copy link
Collaborator

No description provided.

r/DESCRIPTION Outdated
Depends:
R (>= 2.10)
LazyData: true
URL: https://acteng.github.io/od2net/
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBC

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

od2net.org/r?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the repo URL or where the generated documentation will live? https://urban-analytics-technology-platform.github.io/od2net/r/ for the docs; I don't have path forwarding configured on od2net.org yet

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the repo URL or where the generated documentation will live? https://urban-analytics-technology-platform.github.io/od2net/r/ for the docs; I don't have path forwarding configured on od2net.org yet

Correct. Sounds good.

Copy link
Collaborator

@dabreegster dabreegster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm confused about the purpose of a common library in R here. https://github.com/Urban-Analytics-Technology-Platform/od2net/blob/main/examples/utils.py is the Python equivalent so far. The only really interesting method in there is for turning an OSM file into building centroids. The R port has that, and also has a useful helper for downloading + clipping OSM based on the bbox of the zones file. The rest of it all feels like stuff specific to one example. It's making big assumptions about the zone / OD input files. That feels like an example use of the library, not something that belongs in the library, right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it normal to check in generated files?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they are needed for the R tests to pass.

r/R/setup.R Outdated Show resolved Hide resolved
r/R/setup.R Outdated
sf::write_sf(centroids, "input/buildings.geojson", delete_dsn = TRUE)
}

make_od = function() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this hardcoding one particular file? This feels like example code, not something that belongs in a library

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, should be a user-provided file.

r/DESCRIPTION Outdated
Depends:
R (>= 2.10)
LazyData: true
URL: https://acteng.github.io/od2net/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the repo URL or where the generated documentation will live? https://urban-analytics-technology-platform.github.io/od2net/r/ for the docs; I don't have path forwarding configured on od2net.org yet

r/NAMESPACE Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is a generated file checked in?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed for the R package.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Standard practice to check-in this small plaintext file, e.g.: https://github.com/duckdb/duckdb-r/blob/main/NAMESPACE

r/R/setup.R Outdated
#' It will generate a file in the input/ folder
#'
#' @param file Location or URL of zones file
make_zones = function(file) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what this function actually does that's helpful. A user needs to make a GJ file with zones and have a name property on each one. This reads a file, arbitrarily renames one of the properties to name, and writes? That feels very specific / making assumptions about the input

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It assumes that the first column is the name, which is the case with most zone datasets, needs documentation for sure if we do include it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed now.

r/R/setup.R Outdated
sf::write_sf(zones, "input/zones.geojson", delete_dsn = TRUE)
}

getbbox_from_zones = function() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and make_osm do feel like useful functions to be in a common library. They don't make many assumptions about what the user is trying to do.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

r/R/setup.R Outdated
#' @param file File name if hosted on a known site
#' @param base_url Base URL associated with the 'file' argument
#'
make_elevation = function(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also feels too specific to be useful, or it's not really doing much. The user needs to find a geotiff in the correct format. All this function does is download a file and gunzip it. Does it belong in the example and not the common library?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Can remove or move to tutorial...

r/R/setup.R Outdated
}
}

make_origins = function() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call this make_building_centroids or something, and maybe in the docs, call out the caveats with that approach. OSM building coverage is very spotty, and that'll very much affect the results of od2net. That's something the user needs to think about

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, a lot of this can be in the docs, documentation may be more important than the actual functions here.

r/R/setup.R Outdated
readr::write_csv(od, "input/od.csv")
}

main = function() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, does this belong in a library?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, will remove.

@Robinlovelace
Copy link
Collaborator Author

Robinlovelace commented Sep 5, 2024

Thanks for the detailed review @dabreegster, very useful and will improve the experience for R users wanting to use od2net, e.g. as an alternative to the routing/overline approach in the stplanr package. Thinking of iterating on this, moving the less helpful stuff to documentation (folder README being starting point) and acting on the other suggestions above. Sound like a plan?

@dabreegster
Copy link
Collaborator

Yep, sounds good. I think that's a pattern I've seen -- the library has helpers likely to be widely useful, and the end-to-end example can do a bunch of specific stuff

@Robinlovelace
Copy link
Collaborator Author

Checks passing:

image

Copy link
Collaborator

@dabreegster dabreegster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you! Merging

@dabreegster dabreegster merged commit 27fff32 into Urban-Analytics-Technology-Platform:main Sep 10, 2024
@Robinlovelace Robinlovelace deleted the 67-r-port branch September 10, 2024 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants