0

code problem

Save the result from an iteration loop into a whole dataframe problem

library(rscopus)
library(dplyr)

auth_token_header("d2f02ad55dcfc907212f0e6b216bf847")

akey="d2f02ad55dcfc907212f0e6b216bf847"
set_api_key(akey)
df = data.frame(doi = c("10.1109/TPAMI.2018.2798607", "10.1109/CNS.2017.8228696"))

df_references <- NULL
for (i in 1:nrow(df)) {
     x = abstract_retrieval(df$doi[i], identifier= "doi")

     for (a in 1:length(x$content$`abstracts-retrieval-response`$`item`$bibrecord$tail$`bibliography`$reference)){
         call_str <- paste("ref <- x$content$`abstracts-retrieval-response`$`item`$bibrecord$tail$`bibliography`$reference[[",a,"]]$`ref-info`$`ref-title`")
         eval(parse(text = call_str))
         df_references <- rbind(df_references, data.frame(initial_paper = df$doi[i],
                                                          ref_title = ref))
     }
 }

I expect the output to be saved results of every iteration into a dataframe

Elr Mant
  • 507
  • 1
  • 4
  • 14
  • Instead of `df_references <- NULL` try `df_references <- data.frame(initial_paper = character(), ref_title = character())`. That should create the initial dataframe structure so that rbind will work properly in your loop. – Matt Jewett Jan 30 '19 at 16:34
  • @MattJewett unfortunately the error is the same – Elr Mant Jan 30 '19 at 20:35
  • What is the error you receive? – Matt Jewett Jan 30 '19 at 20:37
  • @MattJewett here the error `Error in data.frame(df$doi[i], ref) : arguments imply differing number of rows: 1, 0` – Elr Mant Jan 30 '19 at 20:41
  • should your `df$doi[i]` be `df$doi[a]`, since you are inside the inner loop? – Matt Jewett Jan 30 '19 at 20:45
  • @MattJewett No it i as I would to keep in repeated in every row the x df$doi[i] – Elr Mant Jan 30 '19 at 20:49
  • You could try only doing the rbind if `length(ref) == 1`, it may be that you are running into some instances where you have no ref values being returned and it's causing the creating of the dataframe within the rbind to fail. – Matt Jewett Jan 30 '19 at 20:52

0 Answers0