soc_read: Read a Socrata Dataset into R

View source: R/soc_read.R

soc_readR Documentation

Read a Socrata Dataset into R

Description

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)

Arguments

url

string; URL of the Socrata dataset.

query

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.

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


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"
  )
)



socratadata documentation built on Aug. 8, 2025, 6:08 p.m.