First begin by installing the 2 necessary packages (RISmed and tibble) with install.packages() do this by doing install.packages("RISmed") and install.packages("tibble") Load the packages by using library()
library(RISmed)
## Warning: package 'RISmed' was built under R version 4.0.5
library(tibble)
## Warning: package 'tibble' was built under R version 4.0.5
Set the search query terms: in this case Migraine AND botox AND CGRP. The portion in the quotations mark is what will be edited with each of your new searches. can add to the search critera by using mindate=2000, maxdate=2015, retmax=500 ...etc (mindate is the starting date and maxdate is the ending date of search, retmax sets the amount of responses you can get back).
search_query <- EUtilsSummary("Migraine AND Botox AND CGRP", db = "pubmed")
Look at the search critera that is being used so you can adjust it if need be and see how many results this will retrieve. Can also pull the PMIDs only with the QueryId()
summary(search_query)
## Query:
## ("migraine disorders"[MeSH Terms] OR ("migraine"[All Fields] AND "disorders"[All Fields]) OR "migraine disorders"[All Fields] OR "migraine"[All Fields]) AND ("botulinum toxins, type a"[MeSH Terms] OR "type a botulinum toxins"[All Fields] OR "botox"[All Fields]) AND CGRP[All Fields] 
## 
## Result count:  58
QueryId(search_query)
##  [1] "36114468" "36089629" "36006191" "35879242" "35680766" "35202143"
##  [7] "34877663" "34477213" "34409517" "34130525" "33880725" "33730441"
## [13] "33693863" "33594686" "33567891" "33542885" "33441852" "33434187"
## [19] "33421995" "33348571" "33200944" "33125303" "33121445" "32990477"
## [25] "32731573" "32647152" "32437038" "31835997" "31686633" "31475573"
## [31] "31470791" "30336190" "29671241" "29571276" "29134730" "29131327"
## [37] "28527052" "28497257" "28041540" "27310178" "27300190" "26728188"
## [43] "26493010" "26245187" "25735000" "24673487" "24147647" "23775164"
## [49] "23136725" "23095108" "22862686" "22406987" "22188874" "21459461"
## [55] "21081780" "20728992" "20464603" "15330838"
Pull the results using EUtilsGet with your search & create the object records
records <- EUtilsGet(search_query, type="efetch")
class(records)
## [1] "Medline"
## attr(,"package")
## [1] "RISmed"
Extract the wanted information (title, abstract, PMID, year, author...etc) Additional options Month, Day, Author, ISSN, Language, PublicationStatus, ArticleId, CopyrightInformation, Country, GrantID.
res0 <- tibble(
  'title' = ArticleTitle(records),
  'abstract' = AbstractText(records),
  'PMID' = PMID(records),
  'year' = YearPubmed(records) %>%
    lapply('[[', 1) %>%
    lapply('[[', 1) %>%
    unlist())
Put the extracted information into a csv file It automatically will go to the default folder (documents folder i believe), but if you want it to be in a specific folder you have to set the working directory. This is done by going into the Session tab, click set working directory, then click choose directory, click the folder of your preference.
write.csv(res0, file = "MigraineBotoxCGRPSearch.csv", row.names = FALSE)