在 for 循环中组合 google scholar id 和 pubid

Combining google scholar id and pubid in for loop

我正在使用 R 中的 "scholar" 包。我想为我的研究小组创建一个共同作者的社交网络。我创建了一个数据框研究人员如下:

members <- data.frame(name = c("Linton C Freeman", "Ronald Burt", "Stephen P. Borgatti"),
                      scholar_id = c("quiVMg8AAAAJ", "g-R8XdkAAAAJ", "hlk4a4gAAAAJ"),
                      stringsAsFactors = F)

然后我创建了一个 for 循环来获取每个研究人员的出版物:

pubs <- get_publications(member$scholar_id[1])
for(i in 2:nrow(member)){
           pubs_ <- get_publications(member$scholar_id[i])
           pubs <- rbind(pubs, pubs_)
}

要获得一份不错的合著者列表,我需要使用以下语法:

coauthors <- get_complete_authors(scholar_id, pubid)

例如:

co-authors <- get_complete_authors(members$scholar_id[1], pubs$pubid[1])

我想遍历成员以获取数据框中的所有共同作者。我想我需要先嵌套我的循环,然后遍历 pubs,然后遍历 members。我还需要在我的循环中添加一个暂停语句以避免 HTTP 503 错误。我的问题是如何构建执行此操作的循环?归根结底,我想要一个包含 pubid 和 authors 的数据框。我知道如何从中创建边缘列表。请帮忙。

以下是我将如何使用单个 data.frame 来解决问题以保持一切井井有条。我会这样做,因为它看起来像 Google Scholar 使用相同的 id 来引用不同的出版物,这让生活变得有趣。

library(scholar)
library(tidyverse)

member <- data_frame(name = c("Linton C Freeman", "Ronald Burt", "Stephen P. Borgatti"),
                      scholar_id = c("quiVMg8AAAAJ", "g-R8XdkAAAAJ", "hlk4a4gAAAAJ"))

bib_data <- member %>% 
  #this lets mutate work on each row independently
  rowwise %>% 
  #produce a dataframe for each row
  mutate(pubs = list(get_publications(scholar_id))) %>% 
  #expand the dataframes
  unnest() %>% 
  #I've included this to keep the requests down for a demonstration
  filter(row_number() < 6) %>% 
  #as above
  rowwise %>% 
  #this now uses the scholar_id and pubid from each row to get the coauthor
  #information as a new column
  mutate(coauths = get_complete_authors(scholar_id, pubid))

这样您就可以完全避免 for 循环,并希望所有记录都井井有条。

处理合著者信息是一个不同的挑战,因为看起来格式(尤其是缩写)不一致...