bcdc_get_data {bcdata} | R Documentation |
Download and read a resource from a B.C. Data Catalogue record
Description
Download and read a resource from a B.C. Data Catalogue record
Usage
bcdc_get_data(record, resource = NULL, verbose = TRUE, ...)
Arguments
record |
either a It is advised to use the permanent ID for a record or the BCGW name rather than the
human-readable name to guard against future name changes of the record.
If you use the human-readable name a warning will be issued once per
session. You can silence these warnings altogether by setting an option:
|
resource |
optional argument used when there are multiple data files within the same record. See examples. |
verbose |
When more than one resource is available for a record,
should extra information about those resources be printed to the console?
Default |
... |
arguments passed to other functions. Tabular data is passed to a function to handle
the import based on the file extension. |
Value
An object of a type relevant to the resource (usually a tibble or an sf object, a list if the resource is a json file)
Examples
# Using the record and resource ID:
try(
bcdc_get_data(record = '76b1b7a3-2112-4444-857a-afccf7b20da8',
resource = '4d0377d9-e8a1-429b-824f-0ce8f363512c')
)
try(
bcdc_get_data('1d21922b-ec4f-42e5-8f6b-bf320a286157')
)
# Using a `bcdc_record` object obtained from `bcdc_get_record`:
try(
record <- bcdc_get_record('1d21922b-ec4f-42e5-8f6b-bf320a286157')
)
try(
bcdc_get_data(record)
)
# Using a BCGW name
try(
bcdc_get_data("WHSE_IMAGERY_AND_BASE_MAPS.GSR_AIRPORTS_SVW")
)
# Using sf's sql querying ability
try(
bcdc_get_data(
record = '30aeb5c1-4285-46c8-b60b-15b1a6f4258b',
resource = '3d72cf36-ab53-4a2a-9988-a883d7488384',
layer = 'BC_Boundary_Terrestrial_Line',
query = "SELECT SHAPE_Length, geom FROM BC_Boundary_Terrestrial_Line WHERE SHAPE_Length < 100"
)
)
## Example of correcting import problems
## Some initial problems reading in the data
try(
bcdc_get_data('d7e6c8c7-052f-4f06-b178-74c02c243ea4')
)
## From bcdc_get_record we realize that the data is in xlsx format
try(
bcdc_get_record('8620ce82-4943-43c4-9932-40730a0255d6')
)
## bcdc_read_functions let's us know that bcdata
## uses readxl::read_excel to import xlsx files
try(
bcdc_read_functions()
)
## bcdata let's you know that this resource has
## multiple worksheets
try(
bcdc_get_data('8620ce82-4943-43c4-9932-40730a0255d6')
)
## we can control what is read in from an excel file
## using arguments from readxl::read_excel
try(
bcdc_get_data('8620ce82-4943-43c4-9932-40730a0255d6', sheet = 'Regional Districts')
)
## Pass an argument through to a read_* function
try(
bcdc_get_data(record = "a2a2130b-e853-49e8-9b30-1d0c735aa3d9",
resource = "0b9e7d31-91ff-4146-a473-106a3b301964")
)
## we can control some properties of the list object returned by
## jsonlite::read_json by setting simplifyVector = TRUE or
## simplifyDataframe = TRUE
try(
bcdc_get_data(record = "a2a2130b-e853-49e8-9b30-1d0c735aa3d9",
resource = "0b9e7d31-91ff-4146-a473-106a3b301964",
simplifyVector = TRUE)
)