Create a new Variable object by automatically calculating all metadata from the underlying data. This function is useful when pre-calculated metadata are not available. Note this function will take longer to create variables than other functions because it requires performing geospatial operations.
Usage
new_variable_from_auto(
  dataset,
  index,
  units = "",
  type = "auto",
  colors = "random",
  provenance = "missing",
  labels = "missing",
  hidden = FALSE
)Arguments
- dataset
- Datasetfile path for the dataset.
- index
- characteror- integerindicating the field/layer with the data.
- units
- characterunits for the values in the underlying data.
- type
- characterindicating if the data contain continuous (- "continuous") or categorical (- "categorical") numerical values. Defaults to- "auto"such that data are automatically identified.
- colors
- characterobject containing the colors for visualization (see Details for more information). Defaults to- "random"such that colors are randomly generated.
- provenance
- charactervalue indicating the type of provenance. The argument must be a valid type (see- new_provenance_from_source()). Defaults to- "missing".
- labels
- characterobject containing manual legend labels. Defaults to- "missing".
- logicalindicating if variable will be hidden from map. Defaults to- "FALSE". If hidden, a NullLegend is used
Value
A Variable object.
Details
The argument to colors can be a vector of different colors
(in hexadecimal format, e.g. "#112233"), or a single charactercontaining the name of a color palette that is used to generate a vector of different colors (see [color_palette()] for more information). The color palette name"random"` is also available, such that
colors are generated using a randomly selected palette.
Examples
# find data file paths
f1 <- system.file(
  "extdata", "projects", "sim_raster", "sim_raster_spatial.tif",
  package = "wheretowork"
)
f2 <- system.file(
  "extdata",  "projects", "sim_raster", "sim_raster_attribute.csv.gz",
  package = "wheretowork"
)
f3 <- system.file(
  "extdata",  "projects", "sim_raster", "sim_raster_boundary.csv.gz",
  package = "wheretowork"
)
# create new dataset
d <- new_dataset(f1, f2, f3)
# create new variable
v <- new_variable_from_auto(d, index = 1)
# print object
print(v)
#> Variable
#>   dataset: .../sim_raster_spatial.tif
#>   index:   Brown_necked_Parrot_Brown_necked_
#>   total:   483
#>   units:   
#>   provenance:   missing