write_wikidata: Write statements to Wikidata

Description Usage Arguments Value Examples

View source: R/writes.R

Description

Upload data to wikidata, including creating items, adding statements to existing items (via the quickstatements format and API).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
write_wikidata(
  items,
  properties = NULL,
  values = NULL,
  qual.properties = NULL,
  qual.values = NULL,
  src.properties = NULL,
  src.values = NULL,
  remove = FALSE,
  format = "tibble",
  api.username = NULL,
  api.token = NULL,
  api.format = "v1",
  api.batchname = NULL,
  api.submit = TRUE
)

Arguments

items

a vector of strings indicating the items to which to add statements (as QIDs or labels). Note: if labels are provided, and multiple items match, the first matching item will be used (see as_qid function), so use with caution. New QIDs can be created by using the "CREATE_xyz", where "_xyz" is any unique string. Using the same id will add additional statemnts to those new items

properties

a vector of strings indicating the properties to add as statements (as PIDs or labels). Note: if labels are provided, and multiple items match, the first matching item will be used (see as_pid function), so use with caution. Four special properties can also be used: labels, aliases, descriptions and sitelinks. See [this link](https://www.wikidata.org/wiki/Help:QuickStatements#Adding_labels,_aliases,_descriptions_and_sitelinks) for the syntax.

values

a vector of strings indicating the values to add as statements (as QIDs or strings). Note: if strings are provided, they will be treated as plain text.

qual.properties

a vector, data frame, or tibble of strings indicating the properties to add as qualifiers to statements (as PIDs or labels). Note: if labels are provided, and multiple items match, the first matching item will be used (see as_pid function), so use with caution.

qual.values

a vector, data frame, or tibble of strings indicating the values to add as statements (as QIDs or strings). Note: if strings are provided, they will be treated as plain text.

src.properties

a vector, data frame, or tibble of strings indicating the properties to add as reference sources to statements (as SIDs or labels). Note: if labels are provided, and multiple items match, the first matching item will be used (see as_sid function), so use with caution.

src.values

a vector, data frame, or tibble of strings indicating the values to add reference sources to statements (as QIDs or strings). Note: if strings are provided, they will be treated as plain text.

remove

a vector of boolians for each statemnt indicating whether it should be removed from the item rather than added (default = FALSE)

format

output format as a string. Options include:

tibble

easiest format to further manuipulation in R

csv

can be copy-pasted to [the QuickStatements website](https://quickstatements.toolforge.org/) (or manipulated in a spreadsheet programs)

api

a url that can be copy-pasted into a web browser, or automatically submitted (see api.submit parameter)

website

open a [QuickStatements](https://quickstatements.toolforge.org/) web browser window summarising the edits to be made to Wikidata)

api.username

a string indicating your wikimedia username

api.token

a string indicating your api token (the unique identifier that you can find listed at [your user page](https://quickstatements.toolforge.org/#/user))

api.format

a string indicateing which version of the quickstatement format used to submit the api (default = "v1")

api.batchname

a string create a named batch (listed at [your batch history page](https://quickstatements.toolforge.org/#/batches)) and tag in the edit summaries

api.submit

boolian indicating whether to submit instruction directly to wikidata (else returns the URL that can be copy-pasted into a web browser)

Value

data formatted to upload to wikidata (via quickstatemsnts), optionally also directly uploded to wikidata (see format parameter).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Add a statement to the "Wikidata sandbox" item (Q4115189)
# to say that it is an "instance of" (P31) of Q1 (the universe).
# The instruction will submit directly to wikidata via the API
# (if you include your wikimedia username and token)

write_wikidata(items        = "Wikidata Sandbox",
               properties   = "instance of",
               values       = "Q1",
               format       = "api",
               api.username = "myusername", 
               api.token    = , #REDACTED#
               )
#note: 

WikidataR documentation built on Nov. 16, 2021, 5:07 p.m.