R-ArcGIS / arcgislayers

ArcGIS Location Services
http://r.esri.com/arcgislayers/
Apache License 2.0
37 stars 8 forks source link

Support use of field alias values as column names or label attributes by `arc_read()` #169

Closed elipousson closed 2 months ago

elipousson commented 3 months ago

Is your feature request related to a problem? Please describe.

When used by the creator of a FeatureLayer, field aliases often provide key information about meaning of otherwise confusing field names. These aliases could be used as names for the resulting sf object or as field labels (using the same attribute used by the {labelled} package). arc_read() already has partial support for this when col_names = "alias" but this inadvertently created a bug where you can never rename an attribute to "alias" if it is a single column data frame.

Describe the solution you'd like

I'm adding the proposed solution to the open PR: https://github.com/R-ArcGIS/arcgislayers/pull/167 since it also includes fixes to other aspects of arc_read(). In the PR, the internal set_layer_names function has been renamed set_layer_col_names() and exposes a new "alias" parameter that enables users to drop, replace, or label existing column names using the alias values. Note, there is never an alias for the geometry column (as far as I can tell) so there is never a labelled assigned to geometry.

Describe alternatives you've considered

This could be done using the {labelled} package but keeping the function internal allows for a much more minimal implementation. It could potentially benefit from an alert when column names and alias values are identical but this is very very common so may not be worth it.

You could also allow users to pass labels through a separate argument and get field labels but optionally replace all or some of the the alias values. This may be better handled as a separate option if the function is exported and available for users outside of arc_read() alone.

Additional context

Handling alias values has some similarities to the interest in improving the handling of domain values https://github.com/R-ArcGIS/arcgislayers/issues/134

It is also possible this should be included in arcgisutils package instead as a helper function related to parse_esri_json() or fetch_layer_metadata() or the proposed arc_meta() function https://github.com/R-ArcGIS/arcgislayers/issues/163