Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
^CRAN-RELEASE$
^cran-comments\.md$
^\.httr-oauth$
^LICENSE\.md$
15 changes: 6 additions & 9 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,20 @@ Imports:
WikipediR,
WikidataQueryServiceR,
tibble,
dplyr,
stringr,
Hmisc,
progress,
pbapply,
vctrs,
dplyr,
tidyr,
stats,
readr,
crayon,
utils
Suggests:
markdown,
testthat,
tidyverse,
knitr,
pageviews,
spelling
RoxygenNote: 7.2.3
testthat (>= 3.2.0)
RoxygenNote: 7.3.2
Encoding: UTF-8
Depends: R (>= 3.5.0)
Language: en-US
Config/testthat/edition: 3
11 changes: 2 additions & 9 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
MIT License (https://opensource.org/license/MIT)

Copyright 2014, Oliver Keyes

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
YEAR: 2025
COPYRIGHT HOLDER: WikidataR authors
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# MIT License

Copyright (c) 2025 WikidataR authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
10 changes: 7 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export(write_wikibase)
export(write_wikidata)
import(WikidataQueryServiceR)
import(crayon)
import(dplyr)
import(pbapply)
import(progress)
import(stringr)
Expand All @@ -51,10 +50,15 @@ import(utils)
importFrom(WikipediR,page_content)
importFrom(WikipediR,query)
importFrom(WikipediR,random_page)
importFrom(dplyr,bind_cols)
importFrom(dplyr,first)
importFrom(dplyr,n)
importFrom(dplyr,slice)
importFrom(httr,POST)
importFrom(httr,user_agent)
importFrom(jsonlite,fromJSON)
importFrom(readr,format_delim)
importFrom(readr,format_tsv)
importFrom(stats,cor)
importFrom(stats,var)
importFrom(tidyr,replace_na)
importFrom(vctrs,vec_cbind)
importFrom(vctrs,vec_rbind)
61 changes: 0 additions & 61 deletions NEWS

This file was deleted.

48 changes: 48 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# WikidataR 2.3.0
* New `disambiguate_QIDs()` function for manual item-by-item disambiguation

# WikidataR 2.2.1
* Outputs as tibbles by default with vector options where relevant

# WikidataR 2.2.0
* Additional 'website' output format option for `write_wikidata()` to submit to Quickstatements website
* Patches to make writing wikidata statements with dates more reliable

# WikidataR 2.1.5
* Updated release on CRAN
* Expected property values and constraints from 2.1.0 now just stored as a data file, since onAttach function caused issues

# WikidataR 2.1.0
* Upon loading the package, it will check whether property values are expected to be strings, numbers, dates or QIDs

# WikidataR 2.0.0
* `write_wikidata()` allows you to write to wikidata via the 'quickstatements' format
* Outputs as tibbles where relevant
* Switch maintatiner to Thomas Shafee

# WikidataR 1.4.0
* First release on CRAN!
* `extract_claims()` allows you to, well, extract claims.
* SPARQL syntax bug with some geo queries now fixed (thanks to Mikhail Popov)

# WikidataR 1.3.0
* Vectorisation of `get_*()` functions

# WikidataR 1.2.0
* Geographic data for entities that exist relative to other Wikidata items can now be retrieved
with get_geo_entity and get_geo_box, courtesy of excellent Serena Signorelli's excellent
QueryWikidataR package.
* A bug in printing returned objects is now fixed.

# WikidataR 1.1.0
* You can now retrieve multiple random properties or items with get_random_item and get_random_property

# WikidataR 1.0.1
* Various documentation and metadata improvements.

# WikidataR 1.0.0
* Fix a bug in `get_*()` functions due to a parameter name mismatch
* Print methods added by Christian Graul

# WikidataR 0.5.0
* This is the initial release! See the explanatory vignettes.
17 changes: 6 additions & 11 deletions R/WikidataR.R
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
#' @title API client library for Wikidata
#' @description This package serves as an API client for reading and writing
#' to and from \href{https://www.wikidata.org/wiki/Wikidata:Main_Page}{Wikidata}, (including
#' via the \href{https://quickstatements.toolforge.org/}{QuickStatements} format),
#' as well as for reading from \href{https://www.wikipedia.org}{Wikipedia}.
#' @name WikidataR
#' @docType package
#' @seealso \code{\link{get_random}} for selecting a random item or property,
#' \code{\link{get_item}} for a /specific/ item or property, or \code{\link{find_item}}
#' for using search functionality to pull out item or property IDs where the descriptions
#' or aliases match a particular search term.
#' @import WikidataQueryServiceR
#' @import tibble
#' @import dplyr
#' @import stringr
#' @import pbapply
#' @import progress
#' @import crayon
#' @import utils
#' @importFrom readr format_tsv
#' @importFrom readr format_delim
#' @importFrom dplyr bind_cols
#' @importFrom readr format_tsv format_delim
#' @importFrom vctrs vec_cbind vec_rbind
#' @importFrom stats var
#' @importFrom stats cor
#' @importFrom WikipediR page_content random_page query
#' @importFrom httr user_agent
#' @importFrom httr user_agent POST
#' @importFrom dplyr slice n first
#' @importFrom tidyr replace_na
#' @importFrom jsonlite fromJSON
#' @aliases WikidataR WikidataR-package
NULL
"_PACKAGE"
29 changes: 16 additions & 13 deletions R/geo.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
#'
#'@param limit the maximum number of results to return.
#'
#'@param \\dots further arguments to pass to de{httr:ink[httr::GET]{GET}}.
#'@param ... further arguments to pass to \link[httr:GET]{GET}.
#'
#'@return a data.frame of 5 columns:
#'\itemize{
#'\describe{
#' \item{item}{ the Wikidata identifier of each object associated with
#' \code{entity}.}
#' \item{name}{ the name of the item, if available, in the requested language. If it
Expand All @@ -32,16 +32,18 @@
#'
#'@examples
#'# All entities
#'\donttest{sf_locations <- get_geo_entity("Q62")}
#'\donttest{
#'sf_locations <- get_geo_entity("Q62")
#'
#'# Entities with French, rather than English, names
#'\donttest{sf_locations <- get_geo_entity("Q62", language = "fr")}
#'sf_locations <- get_geo_entity("Q62", language = "fr")
#'
#'# Entities within 1km
#'\donttest{sf_close_locations <- get_geo_entity("Q62", radius = 1)}
#'sf_close_locations <- get_geo_entity("Q62", radius = 1)
#'
#'# Multiple entities
#'\donttest{multi_entity <- get_geo_entity(entity = c("Q62", "Q64"))}
#'multi_entity <- get_geo_entity(entity = c("Q62", "Q64"))
#'}
#'
#'@seealso \code{\link{get_geo_box}} for using a bounding box
#'rather than an unrestricted search or simple radius.
Expand Down Expand Up @@ -112,12 +114,11 @@ get_geo_entity <- function(entity, language = "en", radius = NULL, limit=100, ..
#'@param language the two-letter language code to use for the name
#'of the item. "en" by default.
#'
#'@param \\dots further arguments to pass to de{httr:ink[httr::GET]{GET}}.
#'@param ... further arguments to pass to \link[httr:GET]{GET}.
#'
#'@return a data.frame of 5 columns:
#'\itemize{
#' \item{item}{ the Wikidata identifier of each object associated with
#' \code{entity}.}
#'\describe{
#' \item{item}{ the Wikidata identifier of each object associated with \code{entity}.}
#' \item{name}{ the name of the item, if available, in the requested language. If it
#' is not available, \code{NA} will be returned instead.}
#' \item{latitude}{ the latitude of \code{item}}
Expand All @@ -128,11 +129,13 @@ get_geo_entity <- function(entity, language = "en", radius = NULL, limit=100, ..
#'
#'@examples
#'# Simple bounding box
#'\donttest{bruges_box <- get_geo_box("Q12988", "NorthEast", "Q184287", "SouthWest")}
#'\donttest{
#'bruges_box <- get_geo_box("Q12988", "NorthEast", "Q184287", "SouthWest")
#'
#'# Custom language
#'\donttest{bruges_box_fr <- get_geo_box("Q12988", "NorthEast", "Q184287", "SouthWest",
#' language = "fr")}
#'bruges_box_fr <- get_geo_box("Q12988", "NorthEast", "Q184287", "SouthWest",
#' language = "fr")
#'}
#'
#'@seealso \code{\link{get_geo_entity}} for using an unrestricted search or simple radius,
#'rather than a bounding box.
Expand Down
12 changes: 5 additions & 7 deletions R/gets.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#'it appropriately. This function is vectorized and will happily accept
#'multiple IDs.
#'
#'@param \\dots further arguments to pass to de{httr:ink[httr::GET]{GET}}.
#'@param ... further arguments to pass to \link[httr:GET]{GET}.
#'
#'@seealso \code{\link{get_random}} for selecting a random item or property,
#'or \code{\link{find_item}} for using search functionality to pull out
Expand Down Expand Up @@ -57,7 +57,7 @@ get_property <- function(id, ...){
#'
#'@param limit how many random items to return. 1 by default, but can be higher.
#'
#'@param \\dots arguments to pass to de{httr:ink[httr::GET]{GET}}.
#'@param ... arguments to pass to \link[httr:GET]{GET}.
#'
#'@seealso \code{\link{get_item}} for selecting a specific item or property,
#'or \code{\link{find_item}} for using search functionality to pull out
Expand Down Expand Up @@ -135,12 +135,10 @@ get_example <- function(example_name){
#'
#'@param search_term A term to search for.
#'
#'@param language The language to return the labels and descriptions in; this should
#'consist of an ISO language code. Defaults to \code{"en"}.
#'
#'@inheritParams searcher
#'@param limit The number of results to return; set to \code{10} by default.
#'
#'@param \\dots further arguments to pass to de{httr:ink[httr::GET]{GET}}.
#'@param ... further arguments to pass to \link[httr:GET]{GET}.
#'
#'@seealso \code{\link{get_random}} for selecting a random item or property,
#'or \code{\link{get_item}} for selecting a specific item or property.
Expand Down Expand Up @@ -188,7 +186,7 @@ find_property <- function(search_term,
#'consist of an ISO language code. Set to "en" by default.
#'@param limit the number of results to return; set to 10 by default.
#'@param type type of wikidata object to return (default = "item")
#'@param \\dots Additional parameters to supply to [httr::POST]
#'@param ... Additional parameters to supply to [httr::POST()]
#'@return If the inputted string matches an item label, return its QID.
#'If the inputted string matches multiple labels of multiple items, return the QID of the first hit.
#'If the inputted string is already a QID, return the string.
Expand Down
8 changes: 4 additions & 4 deletions R/queries.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#'@description Utility wrapper for Wikidata API to download item.
#'Used by \code{get_item} and \code{get_property}.
#'@param title The Wikidata item or property as a string.
#'@param \\dots Additional parameters to supply to \code{httr:\link[httr::POST]{POST}}.
#'@param ... Additional parameters to supply to \code{httr:\link[httr:POST]{POST}}.
#'@return A downloaded full wikidata object (item or property) formatted as a
#'nested json list.
#'@export
Expand All @@ -24,7 +24,7 @@ wd_query <- function(title, ...){
#'@param ns string indicating namespace, most commonly "Main" for QID items, "Property"
#'for PID properties.
#'@param limit How many random object to return.
#'@param \\dots Additional parameters to supply to \code{httr:\link[httr::POST]{POST}}.
#'@param ... Additional parameters to supply to \code{httr:\link[httr:POST]{POST}}.
#'@return Downloaded full wikidata objects (items or properties) formatted
#'as nested json lists.
#'@export
Expand All @@ -44,7 +44,7 @@ wd_rand_query <- function(ns, limit, ...){
#'@description Utility wrapper for wikidata spargl endpoint to download items.
#'Used by \code{get_geo_entity} and \code{get_geo_box}.
#'@param query The SPARQL query as a string
#'@param \\dots Additional parameters to supply to \code{httr:\link[httr::POST]{POST}}.
#'@param ... Additional parameters to supply to \code{httr:\link[httr:POST]{POST}}.
#'@return a download of the full wikidata objects formatted as a nested json list
#'@export
sparql_query <- function(query, ...){
Expand All @@ -65,7 +65,7 @@ sparql_query <- function(query, ...){
#' `simple` returns a pure character vector, while
#' `smart` fetches JSON-formatted data and returns a tibble with datetime
#' columns converted to `POSIXct`.
#' @param \\dots Additional parameters to supply to \code{httr:\link[httr::POST]{POST}}.
#' @param ... Additional parameters to supply to \code{httr:\link[httr:POST]{POST}}.
#' @return A `tibble` or `vector`. Note: QID values will be returned as QIDs, rather than URLs.
#' @section Query limits:
#' There is a hard query deadline configured which is set to 60 seconds. There
Expand Down
Loading