-
Notifications
You must be signed in to change notification settings - Fork 10
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 set_layer_coded_values()
and export set_layer_col_names()
#231
Conversation
Also swap argument names layer -> .data and x -> .layer Also fix arc_read example to avoid deprecated use of col_names = "alias"
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.
This is looking pretty good! Thank you! There's a few changes I think we can take to simplify the behavior.
set_layer_col_names()
- We should rename
set_layer_col_names()
I think it is a bit too verbose and thecol
I think is unnecessary because, for better or worse, no one uses row names.- alternative names could be
set_layer_names()
,rename_layer_cols()
- alternative names could be
- The
col_names
argument should be removed. The inclusion of this to me seems like it is smooshingdplyr::rename
orrlang::set_names()
into the same function. Doing so makes the function not have a single purpose but two. I would prefer that this function is designed to specifically rename based on the upstream layer
set_layer_coded_values()
This function seems much more straight forward. I do think that it needs a better name, though. Perhaps we can call it something like encode_from_domains()
or encode_fields()
the idea being that the function is more directly connected to the action being taken on the users behalf.
Testing
Lastly, can we add a few tests for naming? We can create some mocked layer objects too. I'm happy to help there.
nm <- fields[["name"]] | ||
|
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.
Let's check for null nm
here and error out safely
Co-authored-by: Josiah Parry <[email protected]>
- Move col_names handling to dedicated helper set_col_names - Rename set_layer_col_names to set_layer_aliases (remove option to drop aliases) - Rename set_layer_coded_values to encode_field_values - Add call and arg parameters to list_field_domains and pull_coded_values
Took more work than I hoped to disentangle the On reflection, I also don't think |
@elipousson How do you want to handle this? Ideally, the default behavior is do nothing. furl <- "[https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3](vscode-file://vscode-app/Applications/Positron.app/Contents/Resources/app/out/vs/code/electron-sandbox/workbench/workbench.html#)"
res <- arc_read(furl, n_max = 20)
#> Error in `arc_read()`:
#> ! `alias` must be one of "label" or "replace", not "drop". Relatedly it looks like We should probably figure this out within this PR too—scope creep eeek!—so that we're not merging any more bugs. Looks like the logic in For example |
@elipousson are you okay if i take a stab at this a bit? |
I know exactly how the bugs got introduced - I tried to account for both of them but clearly didn’t. To fix the first bug, you can validate alias with arg_match inside of arc_read before calling set_col_names. Have at it if you like or I can get to it tonight or tomorrow! |
- Add `check_col_names()` to simplify input checks - Correctly rename sf_column if lengths match (otherwise use existing value) - Make docs consistent in listing defaults
Got it! |
I've gone ahead and taken the liberty to finish this PR. Note that all exported functions must have an example and also specify the
|
Checklist
devtools::document()
devtools::check()
passes locallyChanges
set_layer_col_names()
(previously used internally byarc_read()
) to allow use of alias values with data returned byarc_select()
(Support use of field alias values as column names or label attributes byarc_read()
#169).set_layer_coded_values()
function to support replacement or labelling of values with coded value domains (Replace domains information #134).Also add helper functions to support
set_layer_coded_values()
:list_field_domains()
pull_pull_coded_values()
Issues that this closes
Partly addresses this issue: #134
There may be a need for functions addressing the other type of domain values and/or validating data for consistency with set domain values before adding data to an existing layer.
Follow up tasks
set_layer_coded_values()
list_field_domains()