Search code examples
rtextminingpubmed

text searching in R


I am trying to make a query to use in a R package named RISmed, which will search and downloaded relevant journal article information from pubmed database. I want to search two words always together, for example :

query= "gene sequencing"
search<-EUtilsSummary(query,type="esearch",db = "pubmed",mindate=2014, maxdate=2014, retmax=20)

If I use, above command, it will search gene and sequencing separately, then both gene and sequencing,that means if in whole text gene and sequencing exists, my command captures them but I want to search in such a way, that it will consider "Gene sequencing", two words always together. How can I write that query? Would anyone please help me?

Thanks in advance !


Solution

  • I would try this:

    query <- '"gene sequencing"[Title/Abstract]'
    

    The pubmed search engine does accept quoted strings and you just need to know how to preserve them within R. Using surrounding single quotes is one method. Using back-slashed quotes would be another. Notice that the returned value from my experiment with your code shows that escape-backslashing is how the implemeters of that package do it:

    > str(search)
    Formal class 'EUtilsSummary' [package "RISmed"] with 6 slots
      ..@ db              : chr "pubmed"
      ..@ count           : num 542
      ..@ retmax          : num 20
      ..@ retstart        : num 0
      ..@ PMID            : chr [1:20] "25548628" "25543043" "25542841" "25540641" ...
      ..@ querytranslation: chr "\"gene sequencing\"[Title/Abstract] AND 2014[EDAT] : 2014[EDAT]"