@andresrcs didn't admonish about reprex
(FAQ: What's a reproducible example (`reprex`) and how do I create one?) Using a reprex, complete with representative data will attract quicker and more answers.
I'll throw in a few suggestions to deal with the malformed issns
. I have to assume, though, that
https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term='2369-2960'
is a well formed query. I can't check that with the API, which I don't have.
-
Although
df$issn
represents a pattern of numerals separated by-
, they are represented ascharacter
objects, rather thannumeric
objects. It's a fine point, but keeping that agnostic orientation makes using character mapping functions easier. -
With more than a handful of separate character patterns, it helps to isolate them in an object, then choose a function to extract them into an object that can be sent to a receiver function.
suppressPackageStartupMessages(library(dplyr))
suppressPackageStartupMessages(library(purrr))
suppressPackageStartupMessages(library(stringr))
# same as df$issn: replicated because df not in namespace here
search_for <- c("2369-2960", "1532-2777", "1876-2026", "1872-7727", "1872-7123", "1532-2777", "1542-7714", "1879-1190", "1090-2139", "1090-2139", "2369-2960")
# string patterns
# lazy programmer kludge on next line
chopoff <- " OR $"
good_form <- "\\d{4}-\\d{4}"
insert <- " OR "
unique(search_for) %>%
str_extract_all(.,good_form) %>%
flatten_chr %>% # _chr because want an error if any numeric objects
str_c(., insert, collapse = "") %>%
str_remove(.,chopoff) -> issns
issns
#> [1] "2369-2960 OR 1532-2777 OR 1876-2026 OR 1872-7727 OR 1872-7123 OR 1542-7714 OR 1879-1190 OR 1090-2139"
Created on 2020-04-05 by the reprex package (v0.3.0)
Now issns
is ready to be passed to EUtilsSummary
as a simple argument. This would be easy to wrap into a function. The virtue is being able to see more clearly into issns
and make further adjustments.