2424# ' @examples
2525# ' # No CSRF needed for Wikidata, but you will need it for Wikibase Suit
2626# ' check_existing_property(
27- # ' search_term="instance of",
28- # ' language = "en",
29- # ' wikibase_api_url="https://www.wikidata.org/w/api.php")
27+ # ' search_term = "instance of",
28+ # ' language = "en",
29+ # ' wikibase_api_url = "https://www.wikidata.org/w/api.php"
30+ # ' )
3031# ' @export
3132
3233check_existing_property <- function (
@@ -39,9 +40,8 @@ check_existing_property <- function(
3940 action = " create_property" ,
4041 log_file_name = NA_character_ ,
4142 data_curator = person(" Unknown" , " Person" ),
42- wikibase_api_url = " https://www.wikidata.org/w/api.php" ,
43- csrf = NULL ) {
44-
43+ wikibase_api_url = " https://www.wikidata.org/w/api.php" ,
44+ csrf = NULL ) {
4545 action_timestamp <- action_timestamp_create()
4646 action_time <- Sys.time()
4747
@@ -61,8 +61,9 @@ check_existing_property <- function(
6161 )
6262
6363 search_response <- httr :: content(get_search ,
64- as = " parsed" ,
65- type = " application/json" )
64+ as = " parsed" ,
65+ type = " application/json"
66+ )
6667
6768 if (! is.null(search_response $ error )) {
6869 stop(paste(search_response $ error $ code , " : " , search_response $ error $ info ))
@@ -87,24 +88,33 @@ check_existing_property <- function(
8788 logical (1 )
8889 )
8990
90- if (sum(exact_match )> 1 ) {
91- stop(" Multiple items [" , paste(matching_props , collapse = " , " ), " ] are matching '" , search_term , " ' in language='" , language , " '." )
91+ if (sum(exact_match ) > 1 ) {
92+ stop(" Multiple items [" , paste(matching_props , collapse = " , " ), " ] are matching '" , search_term , " ' in language='" , language , " '." )
9293 }
9394
94- if (! any(exact_match )) { return (NULL ) }
95- if ( is.null(search_response $ search [[1 ]])) { return (NULL ) }
96- if ( ! is.list(search_response $ search [[1 ]])) { return (NULL ) }
97- if ( is.null(search_response $ search [[which(exact_match )]])) { return (NULL )}
95+ if (! any(exact_match )) {
96+ return (NULL )
97+ }
98+ if (is.null(search_response $ search [[1 ]])) {
99+ return (NULL )
100+ }
101+ if (! is.list(search_response $ search [[1 ]])) {
102+ return (NULL )
103+ }
104+ if (is.null(search_response $ search [[which(exact_match )]])) {
105+ return (NULL )
106+ }
98107
99108 matching_props [exact_match ]
100109
101110 matching_property_data <- search_response $ search [[which(exact_match )]]
102111
103112 if (action %in% c(" create_property" , " copy_property" )) {
104113 datatype <- get_property_definition(matching_property_data $ id , " en" ,
105- wikibase_api_url = wikibase_api_url ,
106- return_type = " data.frame" ,
107- csrf = csrf )$ datatype
114+ wikibase_api_url = wikibase_api_url ,
115+ return_type = " data.frame" ,
116+ csrf = csrf
117+ )$ datatype
108118 comment_text <- glue :: glue(" A property with the label " , search_term , " already exists in this Wikibase." )
109119 }
110120
@@ -187,8 +197,9 @@ check_existing_property <- function(
187197 )
188198 )
189199
190- prefix <- ifelse(wikibase_api_url == " https://www.wikidata.org/w/api.php" ,
191- " wd:" , " wbi:" )
200+ prefix <- ifelse(wikibase_api_url == " https://www.wikidata.org/w/api.php" ,
201+ " wd:" , " wbi:"
202+ )
192203
193204 return_ds $ rowid <- defined(paste0(prefix , as.character(return_ds $ id_on_target )),
194205 namespace = wikibase_api_url
0 commit comments