Skip to contents

Downloads and parses a dataset from a Socrata open data portal URL, returning it as a tibble or sf object. Metadata is also returned as attributes on the returned object.

Usage

soc_read(
  url,
  query = soc_query(),
  alias = "label",
  page_size = 10000,
  include_synthetic_cols = TRUE,
  api_key_id = NULL,
  api_key_secret = NULL
)

Arguments

url

string; URL of the Socrata dataset.

query

string or soc_query(); Query parameters specification

alias

string; Use of field alias values. There are three options:

  • "label": field alias values are assigned as a label attribute for each field.

  • "replace": field alias values replace existing column names.

  • "drop": field alias values replace existing column names.

page_size

whole number; Maximum number of rows returned per request.

include_synthetic_cols

logical; Should synthetic columns be included?

api_key_id

string; API key ID to authenticate requests. (Can also be stored as "soc_api_key_id" environment variable)

api_key_secret

string; API key secret to authenticate requests. (Can also be stored as "soc_api_key_secret" environment variable)

Value

A tibble with additional attributes containing dataset metadata. If the dataset contains a single non-nested geospatial field, it will be returned as an sf object.

The returned object has the following attributes:

id

Asset identifier (four-by-four ID).

name

Asset name.

attribution

Attribution or publisher of the asset.

owner_name

Display name of the asset owner.

provenance

Provenance of asset (official or community).

description

Textual description of the asset.

created

Date asset was created.

data_last_updated

Date asset data was last updated

metadata_last_updated

Date asset metadata was last updated

domain_category

Category label assigned by the domain.

domain_tags

Tags applied by the domain.

domain_metadata

Metadata associated with the asset assigned by the domain.

columns

A dataframe with the following columns:

column_name

Names of asset columns.

column_label

Labels of asset columns.

column_datatype

Datatypes of asset columns.

column_description

Description of asset columns.

permalink

Permanent URL where the asset can be accessed.

link

Direct asset link.

license

License associated with the asset.

Examples

if (FALSE) { # interactive() && httr2::is_online()
soc_read(
  "https://soda.demo.socrata.com/dataset/USGS-Earthquakes-2012-11-08/3wfw-mdbc/"
)

soc_read(
  "https://soda.demo.socrata.com/dataset/USGS-Earthquakes-2012-11-08/3wfw-mdbc/",
  soc_query(
    select = "region, avg(magnitude) as avg_magnitude, count(*) as count",
    group_by = "region",
    having = "count >= 5",
    order_by = "avg_magnitude DESC"
  )
)
}