Skip to contents

Same as tw_filter(), but consistently returns data frames with a single row.

Usage

tw_filter_first(
  search,
  p,
  q,
  language = tidywikidatar::tw_get_language(),
  limit = 10,
  include_search = FALSE,
  wait = 0,
  cache = NULL,
  overwrite_cache = FALSE,
  cache_connection = NULL,
  disconnect_db = TRUE
)

Arguments

search

A data frame generated by tw_search(), or a search query. If a data frame is given, language and limits are ignore.

p

A character vector of length 1, a property. Must always start with the capital letter "P", e.g. "P31" for "instance of".

q

A character vector of length 1, a wikidata id. Must always start with the capital letter "Q", e.g. "Q5" for "human being".

language

Language to be used for the search.

limit

Maximum numbers of responses to be given.

include_search

Logical, defaults to FALSE. If TRUE, the search is returned as an additional column.

wait

In seconds, defaults to 0. Time to wait between queries to Wikidata. If data are cached locally, wait time is not applied. If you are running many queries systematically you may want to add some waiting time between queries.

cache

Defaults to NULL. If given, it should be given either TRUE or FALSE. Typically set with tw_enable_cache() or tw_disable_cache()

overwrite_cache

Defaults to FALSE. If TRUE, overwrites cache.

cache_connection

Defaults to NULL. If NULL, and caching is enabled, tidywikidatar will use a local sqlite database. A custom connection to other databases can be given (see vignette caching for details).

disconnect_db

Defaults to TRUE. If FALSE, leaves the connection to cache open.

Value

A data frame with one row and three columns, id, label, and description, filtered by the above criteria.

Examples

tw_search("Margaret Mead") %>%
  tw_filter_first(p = "P31", q = "Q5")
#> # A tibble: 1 × 3
#>   id      label         description                        
#>   <chr>   <chr>         <chr>                              
#> 1 Q180099 Margaret Mead American anthropologist (1901—1978)