Skip to contents

Makes a POST request to Wikidata Query Service SPARQL endpoint.

Usage

query_wikidata(sparql_query, format = "tibble", ...)

Arguments

sparql_query

SPARQL query (can be a vector of queries)

format

`tibble` (default) returns a pure character data frame, `simple` returns a pure character vector, while `smart` fetches JSON-formatted data and returns a tibble with datetime columns converted to `POSIXct`.

\dots

Additional parameters to supply to httr:POST.

Value

A `tibble` or `vector`. Note: QID values will be returned as QIDs, rather than URLs.

Query limits

There is a hard query deadline configured which is set to 60 seconds. There are also following limits: - One client (user agent + IP) is allowed 60 seconds of processing time each 60 seconds - One client is allowed 30 error queries per minute See query limits section in the Wikidata Query Service User Manual for more information.

Examples

# R's versions and release dates:
sparql_query <- 'SELECT DISTINCT
  ?softwareVersion ?publicationDate
  WHERE {
    BIND(wd:Q206904 AS ?R)
    ?R p:P348 [
      ps:P348 ?softwareVersion;
      pq:P577 ?publicationDate
    ] .
}'
query_wikidata(sparql_query)
#> Rows: 54 Columns: 2
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr  (1): softwareVersion
#> dttm (1): publicationDate
#> 
#>  Use `spec()` to retrieve the full column specification for this data.
#>  Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> # A tibble: 54 × 2
#>    softwareVersion publicationDate
#>    <chr>           <chr>          
#>  1 1.0.0           2000-02-29     
#>  2 2.0.0           2004-10-04     
#>  3 3.0.0           2013-04-03     
#>  4 3.0.1           2013-05-16     
#>  5 3.0.2           2013-09-25     
#>  6 3.0.3           2014-03-06     
#>  7 3.1.0           2014-04-10     
#>  8 3.1.1           2014-07-10     
#>  9 3.1.2           2014-10-31     
#> 10 3.1.3           2015-03-09     
#> # ℹ 44 more rows

if (FALSE) { # \dontrun{
# "smart" format converts all datetime columns to POSIXct
query_wikidata(sparql_query, format = "smart")
} # }