2

I'm using the rscopus package to get data frames for multiple individuals from the Scopus API. To do this I use the author_df function for each individual, then use bind_rows to bind them all together. Sample code is below:

library(rscopus)
library(dplyr)

Elsevier_API = "XXX"
set_api_key(Elsevier_API)

#pull author data frames 
df1 = author_df(au_id = "35392031000", verbose = FALSE, general = FALSE) 
df2 = author_df(au_id = "35418453700", verbose = FALSE, general = FALSE)

#bind dfs
df_final = bind_rows(df1,df2)

This works fine but I do have a list of author ids (au_id in the above code), and would like to be able to set up a function to loop over this list (and eliminate the need for me to manually add new individuals to the script.)

Unfortunately the Scopus API requires an ID key so this will not be reproducible unless you have/register for one.

I'm fairly new to R and coding in general so any help would be greatly appreciated.

Thanks!

  • 2
    I'd use purrr::map_dfr for that. If you're not familiar with the concept of `map` in programming, there are great [instructional videos](https://www.youtube.com/results?search_query=purrr+map_dfr) about it and about the `purrr` package in particular. You will probably run into some rate limiting issues at some point, so you'll probably need to implement some error handling and retry logic, or simply add a long-enough pause in-between your requests. Good luck but essentially this is asking how to loop in R which has been answered 100s of times so I am voting to close. – asachet Jan 11 '21 at 18:00
  • 1
    In your particular case: put your ids in a vector: `au_ids <- c("35392031000", "35418453700")` then map `author_df` to each and bind the results in one line: `df_final <- purrr::map_dfr(au_ids, author_df, verbose = FALSE, general = FALSE)`. This requires the `purrr` package to be installed. Nice first question BTW. – asachet Jan 11 '21 at 18:09
  • Thanks @asachet for the intro to purrr. Worked a treat here. – littletimmy Jan 11 '21 at 21:32

0 Answers0