@@ -87,6 +87,9 @@ copy_wikidata_item <- function(
8787 csrf = NULL ,
8888 wikibase_session = NULL ) {
8989
90+ if (is.null(qid_equivalence_property )) qid_equivalence_property <- NA_character_
91+ validated_action <- " copy_wikidata_item()"
92+
9093 language <- resolve_from_session(" language" , language , wikibase_session )
9194 data_curator <- resolve_from_session(" data_curator" , data_curator , wikibase_session )
9295 log_file_name <- resolve_from_session(" log_file_name" , log_file_name , wikibase_session )
@@ -108,11 +111,10 @@ copy_wikidata_item <- function(
108111 equivalence_id = NA_character_ ,
109112 csrf = csrf ,
110113 data_curator = data_curator ,
111- validated_action = " copy_wikidata_property() "
114+ validated_action = validated_action
112115 )
113116
114- if (is.null(qid_equivalence_property )) qid_equivalence_property <- NA_character_
115-
117+ # Case when multiple items need to be copied ------------
116118 if (length(qid_on_wikidata ) > 1 ) {
117119 return_log_file <- copy_wikidata_items(
118120 qid_on_wikidata = qid_on_wikidata ,
@@ -143,15 +145,13 @@ copy_wikidata_item <- function(
143145 log_file_name <- " "
144146 }
145147
146-
147- # Assert that qid_on_wikidata looks like a QID
148+ # Assert that qid_on_wikidata looks like a QID ----------------------
148149 qid_on_wikidata <- as.character(qid_on_wikidata )
149150 assert_that(is_qid(qid_on_wikidata ),
150151 msg = " qid_on_wikidata must start with Q followed by digits."
151152 )
152153
153154 # Getting the data ---------------------------------------------------------
154-
155155 claim_body <- list (
156156 action = " wbgetentities" ,
157157 ids = qid_on_wikidata ,
@@ -162,6 +162,7 @@ copy_wikidata_item <- function(
162162 # it saves various error exceptions when using httr::POST
163163 safely_post <- purrr :: safely(httr :: POST , NULL )
164164
165+ # The data is always received from Wikidata -------------------
165166 get_claim <- safely_post(
166167 " https://www.wikidata.org/w/api.php" ,
167168 body = claim_body ,
@@ -540,10 +541,15 @@ copy_wikidata_item <- function(
540541 )
541542
542543 if (! is.null(log_file_name ) && nchar(log_file_name ) > 0 ) {
543- write_csv(return_dataframe ,
544+ write.table(
545+ return_dataframe ,
544546 file = log_file_name ,
547+ sep = " ," ,
548+ row.names = FALSE ,
549+ col.names = ! file.exists(log_file_name ),
545550 na = " NA" ,
546- append = TRUE
551+ append = TRUE ,
552+ quote = TRUE
547553 )
548554 }
549555 return_ds
0 commit comments