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
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Imports:
stats,
readr,
crayon,
tidyr,
utils
Suggests:
markdown,
Expand All @@ -42,7 +43,8 @@ Suggests:
knitr,
pageviews,
spelling
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
Encoding: UTF-8
Depends: R (>= 3.5.0)
Language: en-US
Roxygen: list(markdown = TRUE)
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ importFrom(WikipediR,page_content)
importFrom(WikipediR,query)
importFrom(WikipediR,random_page)
importFrom(dplyr,bind_cols)
importFrom(httr,POST)
importFrom(httr,user_agent)
importFrom(jsonlite,fromJSON)
importFrom(readr,format_delim)
Expand Down
29 changes: 15 additions & 14 deletions R/WikidataR.R → R/WikidataR-package.R
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
#' @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
"_PACKAGE"

## usethis namespace: start
#' @import crayon
#' @import dplyr
#' @import stringr
#' @import pbapply
#' @import progress
#' @import crayon
#' @import stringr
#' @import tibble
#' @import utils
#' @importFrom readr format_tsv
#' @importFrom readr format_delim
#' @import WikidataQueryServiceR
#' @importFrom dplyr bind_cols
#' @importFrom stats var
#' @importFrom stats cor
#' @importFrom WikipediR page_content random_page query
#' @importFrom httr POST
#' @importFrom httr user_agent
#' @importFrom jsonlite fromJSON
#' @aliases WikidataR WikidataR-package
NULL
#' @importFrom readr format_delim
#' @importFrom readr format_tsv
#' @importFrom stats cor
#' @importFrom stats var
#' @importFrom WikipediR page_content random_page query
## usethis namespace: end
NULL
9 changes: 4 additions & 5 deletions R/geo.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
#'
#'@param limit the maximum number of results to return.
#'
#'@param \\dots further arguments to pass to de{httr:ink[httr::GET]{GET}}.
#'
#'@inheritDotParams httr::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 Down Expand Up @@ -112,10 +111,10 @@ 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}}.
#'@inheritDotParams httr::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 Down
9 changes: 4 additions & 5 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}}.
#'@inheritDotParams httr::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}}.
#'@inheritDotParams httr::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 @@ -139,8 +139,8 @@ get_example <- function(example_name){
#'consist of an ISO language code. Defaults to \code{"en"}.
#'
#'@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}}.
#'@inheritParams searcher
#'@inheritDotParams httr::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 All @@ -153,7 +153,6 @@ get_example <- function(example_name){
#'#Check for properties involving the peerage
#'peerage_props <- find_property("peerage")
#'
#'@aliases find_item find_property
#'@return A list containing the result of the query.
#'@rdname find_item
#'@export
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}}.
#'@inheritDotParams httr::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}}.
#'@inheritDotParams httr::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}}.
#'@inheritDotParams httr::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}}.
#'@inheritDotParams httr::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
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ as_sid <- function(x){
#'submission to an API.
#'@param x a vector, data frame, or tibble of strings
#'@param format either "tibble" / "csv" to use plain quotation marks (default),
#'or "api" / "website" to use '\%22'
#'or "api" / "website" to use `'\%22'`
#'@return A tibble of items inside of escaped quotation marks
#'unless they are already in escaped quotation marks, is a
#'\href{https://www.wikidata.org/wiki/Q43649390}{QID},
Expand Down
2 changes: 1 addition & 1 deletion R/writes.R
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ write_wikidata <- function(items,
# remove any impossible rows (value is NA)
if(nrow(QS.tib)!=1){
QS.tib <- QS.tib[!is.na(QS.tib$Value),]
QS.tib <- as_tibble(apply(QS.tib,2,replace_na,""))
QS.tib <- as_tibble(apply(QS.tib,2,tidyr::replace_na,""))
}

# format up the output
Expand Down
16 changes: 8 additions & 8 deletions man/WD.globalvar.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 21 additions & 4 deletions man/WikidataR.Rd → man/WikidataR-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/as_qid.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions man/as_quot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/as_sid.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/createrows.tidy.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/disambiguate_QIDs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/filter_qids.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion man/find_item.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions man/get_example.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading