-
Notifications
You must be signed in to change notification settings - Fork 3
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
Added gh_fill.R #35
base: master
Are you sure you want to change the base?
Added gh_fill.R #35
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#' Fill geohash prefix with members | ||
#' | ||
#' @param geohashes Character vector of input geohashes. They must all be of same precision | ||
#' @param precision Positive integer scalar controlling the 'zoom level' – how many characters should be used in the output. | ||
#' @return Character vector of geohashes corresponding to the input. | ||
#' @export | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add examples and tests, it will especially make it easier to review when I can see expected inputs/outputs |
||
|
||
|
||
|
||
gh_fill <- function(geohashes, precision) { | ||
if (uniqueN(nchar(geohashes)) > 1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. uniqueN is a data.table function, which we don't import. |
||
stop("Input Geohashes must all have the same precision level.") | ||
} | ||
if (sum(grepl("['ailo]", geohashes)) > 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. prefer also, elsewhere in the package, we allow upper-case input, we should strive to match case here. |
||
stop("Invalid Geohash; Valid characters: [0123456789bcdefghjkmnpqrstuvwxyz]") | ||
} | ||
|
||
new_levels <- precision - nchar(geohashes[1]) | ||
|
||
base32 <- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's probably better to run this at compile-time in the package environment, rather than every time |
||
unlist(strsplit("0123456789bcdefghjkmnpqrstuvwxyz", split = "")) | ||
|
||
grid <- | ||
do.call(data.table::CJ, append(list(geohashes), replicate(new_levels, base32, FALSE))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you do a performance comparison of Depending on that we'll add the data.table dependency |
||
|
||
do.call(paste0, grid) | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The package isn't currently using roxygen2, so you'll need to either write the .Rd directly, or convert the rest of the package to use roxygen2.