Set column labels or names based FeatureLayer or Table data frame field aliases
Source:R/arc-read.R
set_layer_aliases.Rd
set_layer_aliases()
can replace or label column names based on the the
field aliases from a corresponding Table
or FeatureLayer
object created
with arc_open()
. Optionally repair names using vctrs::vec_as_names()
.
Usage
set_layer_aliases(
.data,
.layer,
name_repair = "unique",
alias = c("replace", "label"),
call = rlang::caller_env()
)
Arguments
- .data
A data frame returned by
arc_select()
orarc_read()
.- .layer
A Table or FeatureLayer object. Required.
- name_repair
Default
"unique"
. Seevctrs::vec_as_names()
for details. Ifname_repair = NULL
andalias = "replace"
may include invalid names.- alias
Use of field alias values. Defaults to
"replace"
. There are two options:"label"
: field alias values are assigned as a label attribute for each field."replace"
: field alias values replace existing column names.
- call
The execution environment of a currently running function, e.g.
caller_env()
. The function will be mentioned in error messages as the source of the error. See thecall
argument ofabort()
for more information.
Value
A data.frame. When alias = "replace"
, the column names are modified.
When alias = "label"
each column has a new label
attribute.
Examples
furl <- paste0(
"https://services.arcgis.com/P3ePLMYs2RVChkJx/ArcGIS/",
"rest/services/USA_Counties_Generalized_Boundaries/FeatureServer/0"
)
# open the feature service
flayer <- arc_open(furl)
# select first five rows
five_counties <- arc_select(flayer, n_max = 5)
# add aliases
with_aliases <- set_layer_aliases(five_counties, flayer)
# preview the new names
str(with_aliases, give.attr = FALSE)
#> Classes ‘sf’ and 'data.frame': 5 obs. of 13 variables:
#> $ OBJECTID : num 1 2 3 4 5
#> $ Name : chr "Autauga County" "Baldwin County" "Barbour County" "Bibb County" ...
#> $ State Name : chr "Alabama" "Alabama" "Alabama" "Alabama" ...
#> $ State FIPS : chr "01" "01" "01" "01" ...
#> $ FIPS : chr "01001" "01003" "01005" "01007" ...
#> $ Area in square miles : num 604 1633 905 626 651
#> $ 2020 Total Population : num 58805 231767 25223 22293 59134
#> $ People per square mile: num 97.3 141.9 27.9 35.6 90.9
#> $ State Abbreviation : chr "AL" "AL" "AL" "AL" ...
#> $ County FIPS : chr "001" "003" "005" "007" ...
#> $ Shape__Area : num 0.149 0.404 0.222 0.158 0.168
#> $ Shape__Length : num 1.88 3.68 2.22 1.85 2.07
#> $ geometry :sfc_POLYGON of length 5; first list element: List of 1
#> ..$ : num [1:39, 1:2] -86.8 -86.8 -86.8 -86.8 -86.9 ...