Avoid failed writing attempts by checking if a label already matches an item.
Usage
check_existing_item(
search_term,
language = "en",
equivalence_property = NA_character_,
equivalence_id = NA_character_,
classification_property = NA_character_,
classification_id = NA_character_,
action = "create_item",
log_file_name = NA_character_,
data_curator = person("Unknown", "Person"),
wikibase_api_url = "https://www.wikidata.org/w/api.php",
csrf = NULL
)Arguments
- search_term
A label in the given language, for example, "Estonia".
- language
A single language code that indicates the language of the label and description, using BCP 47-compliant language tags (e.g., "en" for English, "fr" for French). Defaults to
"en"for English.- equivalence_property
An optional PID of a property already defined in the same Wikibase instance that records the equivalence of this new item with a property defined elsewhere, for example, on Wikidata or CIDOC-CRM. Defaults to
NA_character_; if left missing, no equivalence relations is will be claimed.- equivalence_id
The identifier that uniquely identifies this item among another system's definitions. Defaults to
NA_character_; if left missing, no equivalence relations is will be claimed.- classification_property
The instance of, or subclass of, or superclass of property. Defaults to
NA_characterwhen not used.- classification_id
The QID of the class. Defaults to
NA_characterwhen not used.- action
Defaults to
"create_item".- log_file_name
An explicitly stated full path to a possible CSV log file, defaults to
NULL. If the value isNULL, no log file will be created.- data_curator
The name of the data curator who runs the function and creates the log file, created with person.
- wikibase_api_url
The full URL of the Wikibase API, which is the address that the
wbdatasetR client sends requests to when interacting with the knowledge base. In this case it defaults to'https://www.wikidata.org/w/api.php', Wikidata itself, where no CSRF is needed.- csrf
The CSRF token of your session, received with
get_csrf, not needed ifwikibase_api_url="https://www.wikidata.org/w/api.php". Defaults toNULL.
Details
A wrapper around MediaWiki action=wbsearchentities.
Examples
check_existing_item(
search_term="Estonian National Museum",
language = "en",
wikibase_api_url="https://www.wikidata.org/w/api.php",
csrf=NULL)
#> Person U (2025). "Wikibase Create Item Log (2025-04-03 09:06:42)."
#> rowid action id_on_target label description language datatype wikibase_api_url
#> <hvn> <chr> <hvn_lbl_> <hvn> <hvn_lbl_> <hvn_lb> <chr> <chr>
#> 1 wbi:… creat… Q1370397 Esto… museum in … en wikibas… https://www.wik…
#> # ℹ 8 more variables: equivalence_property <hvn_lbl_>,
#> # equivalence_id <hvn_lbl_>, classification_property <hvn_lbl_>,
#> # classification_id <hvn_lbl_>, success <lgl>, comment <glue>, time <chr>,
#> # logfile <chr>