Search code examples
rpubmed

r run easyPubMed queries row wise from a data frame column


I have a dataframe like below;

enter image description here

I would like to run row by row query in Pubmed using easyPubMed package. For each row/query should fetch list of PMIDs. This list should be retrived in another column called 'PMID'.


Solution

  • This might work

    library(easyPubMed)
    library(purrr)
    Query <- c('rituximab OR bevacizumab','meningitis OR headache')
    Heading <- c('A','B')
    x <- as.data.frame(cbind(Heading,Query),stringsAsFactors = F)
    x$PMID<- ""
    ids <- map(x[,"Query"],get_pubmed_ids)
    for (i in 1:length(ids)) {
      x[i,"PMID"]<- paste(ids[[i]][["IdList"]],collapse = ",")
    }
    

    I think that "sapply" won't return expected results so, going the "map" way from "purrr" package is safer.