diff --git a/.Rbuildignore b/.Rbuildignore index 064ba44..442c2e2 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -6,3 +6,4 @@ ^CRAN-RELEASE$ ^cran-comments\.md$ ^\.httr-oauth$ +^LICENSE\.md$ diff --git a/DESCRIPTION b/DESCRIPTION index 07308e8..d927df2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,50 +1,52 @@ Package: WikidataR -Type: Package Title: Read-Write API Client Library for Wikidata Version: 2.3.3 Date: 2021-11-16 Authors@R: c( - person("Thomas", "Shafee", role = c("aut", "cre"), email = "T.Shafee@latrobe.edu.au", comment = c(ORCID = "0000-0002-2298-7593")), - person("Os", "Keyes", role = "aut", comment = c(ORCID = "0000-0001-5196-609X")), - person("Serena", "Signorelli", role = "aut"), - person("Alex", "Lum", role = "ctb", comment = c(ORCID = "0000-0002-9295-9053")), - person("Christian", "Graul", role = "ctb"), - person("Mikhail", "Popov", role = "ctb", comment = c(ORCID = "0000-0003-0145-8948")) - ) -Description: Read from, interrogate, and write to Wikidata - - the multilingual, interdisciplinary, semantic knowledgebase. Includes functions to: - read from Wikidata (single items, properties, or properties); query Wikidata (retrieving - all items that match a set of criteria via Wikidata SPARQL query service); write to - Wikidata (adding new items or statements via QuickStatements); and handle and manipulate - Wikidata objects (as lists and tibbles). Uses the Wikidata and QuickStatements APIs. -BugReports: https://github.com/TS404/WikidataR/issues -URL: https://github.com/TS404/WikidataR + person("Thomas", "Shafee", , "T.Shafee@latrobe.edu.au", role = c("aut", "cre"), + comment = c(ORCID = "0000-0002-2298-7593")), + person("Os", "Keyes", role = "aut", + comment = c(ORCID = "0000-0001-5196-609X")), + person("Serena", "Signorelli", role = "aut"), + person("Alex", "Lum", role = "ctb", + comment = c(ORCID = "0000-0002-9295-9053")), + person("Christian", "Graul", role = "ctb"), + person("Mikhail", "Popov", role = "ctb", + comment = c(ORCID = "0000-0003-0145-8948")) + ) +Description: Read from, interrogate, and write to Wikidata + - the multilingual, interdisciplinary, + semantic knowledgebase. Includes functions to: read from Wikidata + (single items, properties, or properties); query Wikidata (retrieving + all items that match a set of criteria via Wikidata SPARQL query + service); write to Wikidata (adding new items or statements via + QuickStatements); and handle and manipulate Wikidata objects (as lists + and tibbles). Uses the Wikidata and QuickStatements APIs. License: MIT + file LICENSE +URL: https://github.com/TS404/WikidataR +BugReports: https://github.com/TS404/WikidataR/issues +Depends: + R (>= 3.5.0) Imports: + crayon, + dplyr, httr, jsonlite, - WikipediR, - WikidataQueryServiceR, - tibble, - dplyr, - stringr, - Hmisc, - progress, pbapply, + progress, + readr (>= 2.0.0), stats, - readr, - crayon, + stringr, + tibble, tidyr, - utils + utils, + vctrs, + WikidataQueryServiceR, + WikipediR Suggests: - markdown, - testthat, - tidyverse, - knitr, - pageviews, - spelling -RoxygenNote: 7.3.2 + testthat (>= 3.2.0) +Config/testthat/edition: 3 Encoding: UTF-8 -Depends: R (>= 3.5.0) Language: en-US Roxygen: list(markdown = TRUE) +RoxygenNote: 7.3.3 diff --git a/LICENSE b/LICENSE index 4ba24c1..4953c18 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..a761067 --- /dev/null +++ b/LICENSE.md @@ -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. diff --git a/NAMESPACE b/NAMESPACE index 07d64e3..cab8525 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -51,7 +51,6 @@ import(utils) 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) @@ -59,3 +58,5 @@ importFrom(readr,format_delim) importFrom(readr,format_tsv) importFrom(stats,cor) importFrom(stats,var) +importFrom(vctrs,vec_cbind) +importFrom(vctrs,vec_rbind) diff --git a/NEWS b/NEWS deleted file mode 100644 index b001a20..0000000 --- a/NEWS +++ /dev/null @@ -1,61 +0,0 @@ -2.3.0 -================================================= -* New disambiguate_QIDs() function for manual item-by-item disambiguation - -2.2.1 -================================================= -* Outputs as tibbles by default with vector options where relevant - -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 - -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 - -2.1.0 -================================================= -* Upon loading the package, it will check whether property values are expected to be strings, numbers, dates or QIDs - -2.0.0 -=================================================w -* Write_wikidata() allows you to write to wikidata via the 'quickstatements' format -* Outputs as tibbles where relevant -* Switch maintatiner to Thomas Shafee - -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) - -1.3.0 -================================================= -* Vectorisation of get_*() functions - -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. - -1.1.0 -================================================= -* You can now retrieve multiple random properties or items with get_random_item and get_random_property - -1.0.1 -================================================= -* Various documentation and metadata improvements. - -1.0.0 -================================================= -* Fix a bug in get_* functions due to a parameter name mismatch -* Print methods added by Christian Graul - -0.5.0 -================================================= -* This is the initial release! See the explanatory vignettes. diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..77ad212 --- /dev/null +++ b/NEWS.md @@ -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. diff --git a/R/WikidataR-package.R b/R/WikidataR-package.R index 7c0d252..d12c17c 100644 --- a/R/WikidataR-package.R +++ b/R/WikidataR-package.R @@ -17,7 +17,7 @@ #' @import tibble #' @import utils #' @import WikidataQueryServiceR -#' @importFrom dplyr bind_cols +#' @importFrom vctrs vec_cbind vec_rbind #' @importFrom httr POST #' @importFrom httr user_agent #' @importFrom jsonlite fromJSON diff --git a/R/disambiguators.R b/R/disambiguators.R index 51f2924..1f6bbdb 100644 --- a/R/disambiguators.R +++ b/R/disambiguators.R @@ -72,7 +72,7 @@ disambiguate_QIDs <- function(list, #is the list the outut from a previous half-done run? if(any(unlist(lapply(list,function(x) x=="STOP")),na.rm = TRUE)){ item_to_start_from <- which(unlist(lapply(list,function(x) any(x=="STOP")))) - subitem_to_start_from <- first(which(list == "STOP")) + subitem_to_start_from <- dplyr::first(which(list == "STOP")) output <- list }else{ item_to_start_from <- 1 diff --git a/R/geo.R b/R/geo.R index 7c42ecf..d97679e 100644 --- a/R/geo.R +++ b/R/geo.R @@ -31,16 +31,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. @@ -127,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. diff --git a/R/gets.R b/R/gets.R index 425a4d4..0d7e3ef 100644 --- a/R/gets.R +++ b/R/gets.R @@ -135,10 +135,6 @@ 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"}. -#' -#'@param limit The number of results to return; set to \code{10} by default. #'@inheritParams searcher #'@inheritDotParams httr::GET #' @@ -187,7 +183,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. diff --git a/R/queries.R b/R/queries.R index 0d78f33..541fbc8 100644 --- a/R/queries.R +++ b/R/queries.R @@ -161,10 +161,12 @@ qid_from_identifier <- function(property = 'DOI', #' @param value The identifier value to match. #' @return A vector of identifiers corresponding to identifiers submitted. #' @examples +#' \donttest{ #' identifier_from_identifier(property ='ORCID iD', #' return = 'IMDb ID', #' value = c('0000-0002-7865-7235','0000-0003-1079-5604') #' ) +#' } #' @export identifier_from_identifier <- function(property = 'ORCID iD', return = 'IMDb ID', diff --git a/R/utils.R b/R/utils.R index b21f936..b24178f 100644 --- a/R/utils.R +++ b/R/utils.R @@ -66,7 +66,7 @@ check_input <- function(input, substitution){ # -------- Format converters -------- # Simple functions to convert plain text descriptions into their most likely QID/PIDs -#'@title Convert an input to a item QID. +#'@title Convert an input to a item QID #'@description Convert an input string to the most likely item #'\href{https://www.wikidata.org/wiki/Q43649390}{QID}. #'@param x a vector, data frame, or tibble of strings representing wikidata items @@ -116,7 +116,7 @@ as_qid <- function(x){ out <- unlist(lapply(x,as_qid_nest2)) out } - output <- bind_cols(lapply(tibble(x),as_qid_nest1)) + output <- vec_cbind(lapply(tibble(x),as_qid_nest1)) return(output) } @@ -158,7 +158,7 @@ as_pid <- function(x){ out <- unlist(lapply(x,as_pid_nest2)) out } - output <- bind_cols(lapply(tibble(x),as_pid_nest1)) + output <- vec_cbind(lapply(tibble(x),as_pid_nest1)) return(output) } @@ -193,7 +193,7 @@ as_sid <- function(x){ out <- unlist(lapply(x,as_sid_nest2)) out } - output <- bind_cols(lapply(tibble(x),as_sid_nest1)) + output <- vec_cbind(lapply(tibble(x),as_sid_nest1)) return(output) } @@ -228,7 +228,7 @@ as_quot <- function(x,format="tibble"){ out <- unlist(lapply(x,as_quot_nest2)) out } - output <- bind_cols(lapply(tibble(x),as_quot_nest1)) + output <- vec_cbind(lapply(tibble(x),as_quot_nest1)) return(output) } @@ -390,7 +390,7 @@ filter_qids <- function (ids, }else{ desc <- "no description" } - out <- bind_rows(out,tibble(qid=qid,label=label,desc=desc)) + out <- vec_rbind(out,tibble(qid=qid,label=label,desc=desc)) } }else{ for (i in 1:length(ids)){ @@ -419,7 +419,7 @@ filter_qids <- function (ids, }else{ label <- "no label" } - out <- bind_rows(out,tibble(qid=qid,label=label,desc=desc)) + out <- vec_rbind(out,tibble(qid=qid,label=label,desc=desc)) } } } @@ -458,7 +458,7 @@ unspecial <- function(x){ out <- x for(i in 1:ncol(x)){ out[[i]] <- iconv(x[[i]],to = 'ASCII//TRANSLIT') - if(Hmisc::all.is.numeric(x[[i]])){ + if(all_numeric(x[[i]])){ out[[i]] <- as.numeric(out[[i]]) }else{ out[[i]] <- as.factor(out[[i]]) @@ -528,7 +528,7 @@ createrows <- function(items,vector){ vector <- tibble(vector) newQID <- which(items=="CREATE") - val <- bind_rows(vector,tibble(data.frame(array("",dim=c(length(newQID),ncol(vector)),dimnames = list(NULL,colnames(vector)))))) + val <- vec_rbind(vector,tibble(data.frame(array("",dim=c(length(newQID),ncol(vector)),dimnames = list(NULL,colnames(vector)))))) id <- c(1:nrow(vector), newQID-seq_along(newQID)+0.5) out <- tibble(val[order(id),]) return(out) @@ -560,3 +560,18 @@ createrows.tidy <- function(QS.tib){ out[apply(is.empty(out),all,MARGIN=1),1] <- "CREATE" return(out) } + + +all_numeric <- function(x) { + x <- sub("[[:space:]]+$", "", x) + x <- sub("^[[:space:]]+", "", x) + # remove empty + xs <- x[nzchar(x)] + + if (length(xs) == 0 || all(is.na(x))) { + return(FALSE) + } + + isnon <- suppressWarnings(!is.na(xs) & is.na(as.numeric(xs))) + !any(isnon) +} diff --git a/R/writes.R b/R/writes.R index 764156a..3c1dd49 100644 --- a/R/writes.R +++ b/R/writes.R @@ -112,9 +112,9 @@ write_wikidata <- function(items, if(var(unlist(rowcount))!=0){ for (x in 1:length(QS)){ if(is.null(nrow(QS[[x]]))){ - QS[[x]] <- slice(tibble(QS[[x]]),rep(1:n(), each=rowmax)) + QS[[x]] <- dplyr::slice(tibble(QS[[x]]),rep(1:dplyr::n(), each=rowmax)) }else if (nrow(QS[[x]])==1){ - QS[[x]] <- slice(tibble(QS[[x]]),rep(1:n(), each=rowmax)) + QS[[x]] <- dplyr::slice(tibble(QS[[x]]),rep(1:dplyr::n(), each=rowmax)) }else if(nrow(QS[[x]])==rowmax){ QS[[x]] <- QS[[x]] }else{ @@ -162,7 +162,7 @@ write_wikidata <- function(items, colnames(QS$properties) <- "Prop" colnames(QS$values) <- "Value" - QS.tib <- bind_cols(QS$items, + QS.tib <- vec_cbind(QS$items, QS$properties, QS$values) @@ -230,7 +230,7 @@ write_wikidata <- function(items, } if (format=="website"){ - api.temp1 <- format_tsv(QS.tib, col_names = FALSE, quote_escape = "none") + api.temp1 <- format_tsv(QS.tib, col_names = FALSE, escape = "none") api.temp2 <- gsub("\t", "%7C",api.temp1) # Replace TAB with "%7C" api.temp3 <- gsub("%7C(%7C)+","%7C",api.temp2) # Replace multiple tabs (from missing values) with a single tab (to distinguish from newlines) api.temp4 <- gsub("\n", "%7C%7C",api.temp3) # Replace end-of-line with "%7C%7C" @@ -248,7 +248,7 @@ write_wikidata <- function(items, } if (format=="api"){ - api.temp1 <- format_tsv(QS.tib, col_names = FALSE, quote_escape = "none") + api.temp1 <- format_tsv(QS.tib, col_names = FALSE, escape = "none") api.temp2 <- gsub("%22","\"",api.temp1) #cludge to fix as_quote issues api.data <- gsub("%2F","/",api.temp2) #cludge to fix as_date issues @@ -264,7 +264,7 @@ write_wikidata <- function(items, ) browseURL("https://quickstatements.toolforge.org/#/batches") }else{ - api.temp1 <- format_tsv(QS.tib, col_names = FALSE, quote_escape = "none") + api.temp1 <- format_tsv(QS.tib, col_names = FALSE, escape = "none") api.temp2 <- gsub("\t", "%7C",api.temp1) # Replace TAB with "%7C" api.temp3 <- gsub("%7C(%7C)+","%7C",api.temp2) # Replace multiple tabs (from missing values) with a single tab (to distinguish from newlines) api.temp4 <- gsub("\n", "%7C%7C",api.temp3) # Replace end-of-line with "%7C%7C" diff --git a/R/writes_wikibase.R b/R/writes_wikibase.R index f3bdb46..c2e00e4 100644 --- a/R/writes_wikibase.R +++ b/R/writes_wikibase.R @@ -129,7 +129,7 @@ write_wikibase <- function(items, if (nrow(QS[[x]]) == rowmax) { QS[[x]] <- QS[[x]] } else if (nrow(QS[[x]]) == 1) { - QS[[x]] <- slice(QS[[x]], rep(1:n(), each = rowmax)) + QS[[x]] <- dplyr::slice(QS[[x]], rep(1:dplyr::n(), each = rowmax)) } else { stoprun <- TRUE warning(paste0( @@ -163,7 +163,7 @@ write_wikibase <- function(items, colnames(QS$properties) <- "Prop" colnames(QS$values) <- "Value" - QS.tib <- bind_cols( + QS.tib <- vec_cbind( QS$items, QS$properties, QS$values diff --git a/WikidataR.Rproj b/WikidataR.Rproj index 168aa81..3cca442 100644 --- a/WikidataR.Rproj +++ b/WikidataR.Rproj @@ -12,6 +12,8 @@ Encoding: UTF-8 RnwWeave: Sweave LaTeX: XeLaTeX +AutoAppendNewline: Yes + BuildType: Package PackageUseDevtools: Yes PackageInstallArgs: --no-multiarch --with-keep.source --resave-data=best diff --git a/man/as_qid.Rd b/man/as_qid.Rd index aa0c276..3143ece 100644 --- a/man/as_qid.Rd +++ b/man/as_qid.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/utils.R \name{as_qid} \alias{as_qid} -\title{Convert an input to a item QID.} +\title{Convert an input to a item QID} \usage{ as_qid(x) } diff --git a/man/find_item.Rd b/man/find_item.Rd index 93fee87..b10ac96 100644 --- a/man/find_item.Rd +++ b/man/find_item.Rd @@ -23,10 +23,10 @@ find_property( \arguments{ \item{search_term}{A term to search for.} -\item{language}{The language to return the labels and descriptions in; this should -consist of an ISO language code. Defaults to \code{"en"}.} +\item{language}{the language to conduct the search in; this should +consist of an ISO language code. Set to "en" by default.} -\item{limit}{The number of results to return; set to \code{10} by default.} +\item{limit}{the number of results to return; set to 10 by default.} \item{response_language}{the language to return the labels and descriptions in; this should consist of an ISO language code. Set to "en" by default.} diff --git a/man/get_example.Rd b/man/get_example.Rd index 6138525..6fccf88 100644 --- a/man/get_example.Rd +++ b/man/get_example.Rd @@ -34,5 +34,5 @@ query_wikidata(sparql_query) } } \seealso{ -\link{query_wikidata} +\link[WikidataQueryServiceR:query_wikidata]{WikidataQueryServiceR::query_wikidata} } diff --git a/man/get_geo_box.Rd b/man/get_geo_box.Rd index 4caf8e1..916d81d 100644 --- a/man/get_geo_box.Rd +++ b/man/get_geo_box.Rd @@ -66,11 +66,13 @@ with geographic attributes (usually cities). } \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{ diff --git a/man/get_geo_entity.Rd b/man/get_geo_entity.Rd index d01e8be..732ee87 100644 --- a/man/get_geo_entity.Rd +++ b/man/get_geo_entity.Rd @@ -57,16 +57,18 @@ a city). } \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{ diff --git a/man/identifier_from_identifier.Rd b/man/identifier_from_identifier.Rd index 3c980ad..3c6b0e5 100644 --- a/man/identifier_from_identifier.Rd +++ b/man/identifier_from_identifier.Rd @@ -24,8 +24,10 @@ A vector of identifiers corresponding to identifiers submitted. Convert unique identifiers to other unique identifiers. } \examples{ +\donttest{ identifier_from_identifier(property ='ORCID iD', return = 'IMDb ID', value = c('0000-0002-7865-7235','0000-0003-1079-5604') ) } +} diff --git a/man/searcher.Rd b/man/searcher.Rd index dfe2d27..986e189 100644 --- a/man/searcher.Rd +++ b/man/searcher.Rd @@ -19,7 +19,7 @@ consist of an ISO language code. Set to "en" by default.} \item{type}{type of wikidata object to return (default = "item")} -\item{\\dots}{Additional parameters to supply to \link[httr:POST]{httr::POST}} +\item{...}{Additional parameters to supply to \code{\link[httr:POST]{httr::POST()}}} } \value{ If the inputted string matches an item label, return its QID. diff --git a/tests/testthat.R b/tests/testthat.R index 34fbd73..485b927 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,3 +1,11 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + library(testthat) library(WikidataR) diff --git a/tests/testthat/test_geo.R b/tests/testthat/test_geo.R index b1a75de..f90394f 100644 --- a/tests/testthat/test_geo.R +++ b/tests/testthat/test_geo.R @@ -1,50 +1,52 @@ -testthat::context("Geographic queries") -# Have had to comment out tests. Wikidata query service having timeout issues that cause tests to fail +# Geographic queries ----- +# Skipping tests on CI and on CRAN to ensure no API rate limit +skip_on_ci() +skip_on_cran() -# testthat::test_that("Simple entity-based geo lookups work", { -# field_names <- c("item", "name", "latitutde", "longitude", "entity") -# sf_locations <- get_geo_entity("Q62") -# testthat::expect_true(is.data.frame(sf_locations)) -# testthat::expect_true(all(field_names == names(sf_locations))) -# testthat::expect_true(unique(sf_locations$entity) == "Q62") -# }) +testthat::test_that("Simple entity-based geo lookups work", { + field_names <- c("item", "name", "latitutde", "longitude", "entity") + sf_locations <- get_geo_entity("Q62") + testthat::expect_true(is.data.frame(sf_locations)) + testthat::expect_true(all(field_names == names(sf_locations))) + testthat::expect_true(unique(sf_locations$entity) == "Q62") +}) -# testthat::test_that("Language-variant entity-based geo lookups work", { -# field_names <- c("item", "name", "latitutde", "longitude", "entity") -# sf_locations <- get_geo_entity("Q62", language = "fr") -# testthat::expect_true(is.data.frame(sf_locations)) -# testthat::expect_true(all(field_names == names(sf_locations))) -# testthat::expect_true(unique(sf_locations$entity) == "Q62") -# }) +testthat::test_that("Language-variant entity-based geo lookups work", { + field_names <- c("item", "name", "latitutde", "longitude", "entity") + sf_locations <- get_geo_entity("Q62", language = "fr") + testthat::expect_true(is.data.frame(sf_locations)) + testthat::expect_true(all(field_names == names(sf_locations))) + testthat::expect_true(unique(sf_locations$entity) == "Q62") +}) -# testthat::test_that("Radius restricted entity-based geo lookups work", { -# field_names <- c("item", "name", "latitutde", "longitude", "entity") -# sf_locations <- get_geo_entity("Q62", radius = 1) -# testthat::expect_true(is.data.frame(sf_locations)) -# testthat::expect_true(all(field_names == names(sf_locations))) -# testthat::expect_true(unique(sf_locations$entity) == "Q62") -# }) +testthat::test_that("Radius restricted entity-based geo lookups work", { + field_names <- c("item", "name", "latitutde", "longitude", "entity") + sf_locations <- get_geo_entity("Q62", radius = 1) + testthat::expect_true(is.data.frame(sf_locations)) + testthat::expect_true(all(field_names == names(sf_locations))) + testthat::expect_true(unique(sf_locations$entity) == "Q62") +}) -# testthat::test_that("multi-entity geo lookups work", { -# field_names <- c("item", "name", "latitutde", "longitude", "entity") -# sf_locations <- get_geo_entity(c("Q62", "Q64"), radius = 1) -# testthat::expect_true(is.data.frame(sf_locations)) -# testthat::expect_true(all(field_names == names(sf_locations))) -# testthat::expect_equal(length(unique(sf_locations$entity)), 2) -# }) +testthat::test_that("multi-entity geo lookups work", { + field_names <- c("item", "name", "latitutde", "longitude", "entity") + sf_locations <- get_geo_entity(c("Q62", "Q64"), radius = 1) + testthat::expect_true(is.data.frame(sf_locations)) + testthat::expect_true(all(field_names == names(sf_locations))) + testthat::expect_equal(length(unique(sf_locations$entity)), 2) +}) -# testthat::test_that("Simple bounding lookups work", { -# field_names <- c("item", "name", "latitutde", "longitude") -# bruges_box <- get_geo_box("Q12988", "NorthEast", "Q184287", "SouthWest") -# testthat::expect_true(is.data.frame(bruges_box)) -# testthat::expect_true(all(field_names == names(bruges_box))) -# }) +testthat::test_that("Simple bounding lookups work", { + field_names <- c("item", "name", "latitutde", "longitude") + bruges_box <- get_geo_box("Q12988", "NorthEast", "Q184287", "SouthWest") + testthat::expect_true(is.data.frame(bruges_box)) + testthat::expect_true(all(field_names == names(bruges_box))) +}) -# testthat::test_that("Language-variant bounding lookups work", { -# field_names <- c("item", "name", "latitutde", "longitude") -# bruges_box <- get_geo_box("Q12988", "NorthEast", "Q184287", "SouthWest", -# language = "fr") -# testthat::expect_true(is.data.frame(bruges_box)) -# testthat::expect_true(all(field_names == names(bruges_box))) -# }) \ No newline at end of file +testthat::test_that("Language-variant bounding lookups work", { + field_names <- c("item", "name", "latitutde", "longitude") + bruges_box <- get_geo_box("Q12988", "NorthEast", "Q184287", "SouthWest", + language = "fr") + testthat::expect_true(is.data.frame(bruges_box)) + testthat::expect_true(all(field_names == names(bruges_box))) +}) diff --git a/tests/testthat/test_gets.R b/tests/testthat/test_gets.R index 2164d4b..5f32521 100644 --- a/tests/testthat/test_gets.R +++ b/tests/testthat/test_gets.R @@ -1,19 +1,19 @@ -context("Direct Wikidata get functions") +# Direct Wikidata get functions ---- test_that("A specific item can be retrieved with an entire item code", { - expect_true({get_item("Q100");TRUE}) + expect_no_error(get_item("Q100")) }) test_that("A specific item can be retrieved with a partial entire item code", { - expect_true({get_item("100");TRUE}) + expect_no_error(get_item("100")) }) test_that("A specific property can be retrieved with an entire prop code + namespace", { - expect_true({get_property("Property:P10");TRUE}) + expect_no_error(get_property("Property:P10")) }) test_that("A specific property can be retrieved with an entire prop code + namespace", { - expect_true({get_property("P10");TRUE}) + expect_no_error(get_property("P10")) }) @@ -27,4 +27,4 @@ test_that("A randomly-selected item can be retrieved",{ test_that("A randomly-selected property can be retriveed",{ expect_true({get_random_property();TRUE}) -}) \ No newline at end of file +}) diff --git a/tests/testthat/test_search.R b/tests/testthat/test_search.R index 8d8798f..0b95bcc 100644 --- a/tests/testthat/test_search.R +++ b/tests/testthat/test_search.R @@ -1,13 +1,13 @@ -context("Search functions") +# test search functions test_that("English-language search works",{ - expect_true({find_item("Wonder Girls", "en");TRUE}) + expect_no_error(find_item("Wonder Girls", "en")) }) test_that("Non-English-language search works",{ - expect_true({find_item("Wonder Girls", "es");TRUE}) + expect_no_error(find_item("Wonder Girls", "es")) }) test_that("Property search works",{ - expect_true({find_property("Music", "en");TRUE}) -}) \ No newline at end of file + expect_no_error(find_property("Music", "en")) +})