Skip to contents

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

Usage

write_wikibase(
  items,
  properties = NULL,
  values = NULL,
  qual.properties = NULL,
  qual.values = NULL,
  src.properties = NULL,
  src.values = NULL,
  remove = FALSE,
  format = "tibble",
  format.csv.file = NULL,
  api.username = NULL,
  api.token = NULL,
  api.format = "v1",
  api.batchname = NULL,
  api.submit = TRUE,
  quickstatements.url = NULL,
  coordinate_pid = NULL
)

Arguments

items

a vector of strings indicating the items to which to add statements (as QIDs or labels). Note: In contrast to write_wikidata, this function takes no labels as input, just QIDs. New QIDs can be created by using the "CREATE_xyz", where "_xyz" is any unique string. Using the same id will add additional statements to those new items

properties

a vector of strings indicating the properties to add as statements (as PIDs or labels). Note: In contrast to write_wikidata, this function takes no labels as input, just PIDs. 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). 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).

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 boolean values for each statement 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 manipulation in R

csv

can be copy-pasted to the Wikibase QuickStatements website (or manipulated in a spreadsheet programs). In contrast to write_wikidata function the delimiter is `tab`, because Quickstatements expect tab-separated data

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 summarizing the edits to be made to Wikidata)

format.csv.file

path to save the csv file. If none is provided, then printed to console.

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

quickstatements.url

url to access quickstatements of the corresponding Wikibase instance.

coordinate_pid

PID of a geocoordinates; need to have a different formatting

Value

data formatted to upload to Wikidata (via QuickStatements), optionally also directly uploaded to Wikidata (see format parameter).

Examples

# 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 Wikibase/Wikimedia username and token)

if (FALSE) { # \dontrun{
write_wikibase(
  items = "Q24",
  properties = "P2",
  values = "Q8",
  format = "api",
  api.username = "myusername",
  api.token = "mytoken",
  api.submit = TRUE,
  quickstatements.url = NULL
)
} # }
# note: