Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Boolean composition operators for esearch with web_history objects #167

Open
billdenney opened this issue Jan 28, 2021 · 0 comments

Comments

@billdenney
Copy link

In my use case, I need to create a complex query that will likely require creating many smaller queries first and combining them with a web_history. (Specifically, I'm doing a search for many medications, and then I want to look for drug-drug interactions between them, pairwise.)

For that, it would be helpful to be able to create a new search from multiple esearch objects that have a web_history.

Specifically, what I'm thinking of is to be able to simplify the last two lines of this:

library(rentrez)

query_part1 <- "(adolescent[Title/Abstract] OR adolescents[Title/Abstract] OR apprentice[Title/Abstract] OR apprentices[Title/Abstract] OR child[Title/Abstract] OR children[Title/Abstract] OR pupil[Title/Abstract] OR pupils[Title/Abstract] OR student[Title/Abstract] OR students[Title/Abstract] OR teenager[Title/Abstract] OR teenagers[Title/Abstract] OR trainee[Title/Abstract] OR trainees[Title/Abstract] OR young adult[Title/Abstract] OR young adults[Title/Abstract] OR young people[Title/Abstract] OR young worker[Title/Abstract] OR young workers[Title/Abstract] OR younger population[Title/Abstract] OR youth[Title/Abstract])"
query_part3 <- "(frequency[Title/Abstract] OR frequencys[Title/Abstract] OR occurence[Title/Abstract] OR prevalence[Title/Abstract] OR prevalences[Title/Abstract] OR rate[Title/Abstract] OR rates[Title/Abstract] OR risk[Title/Abstract] OR risks[Title/Abstract])"

q1 <- entrez_search(db="pubmed", term=query_part1, use_history=TRUE)
q3 <- entrez_search(db="pubmed", term=query_part3, use_history=TRUE, WebEnv=q1$web_history$WebEnv)

query_combine_1_3 <- sprintf("#%s AND #%s", q1$web_history$QueryKey, q3$web_history$QueryKey)
q1_3 <- entrez_search(db="pubmed", term=query_combine_1_3, use_history=TRUE, WebEnv=q1$web_history$WebEnv)

I'd like to be able to replace:

query_combine_1_3 <- sprintf("#%s AND #%s", q1$web_history$QueryKey, q3$web_history$QueryKey)
q1_3 <- entrez_search(db="pubmed", term=query_combine_1_3, use_history=TRUE, WebEnv=q1$web_history$WebEnv)

With:

q1_3 <- q1 & q3

What would happen under the hood would look a lot like the code that I gave above:

  • Extract the web_history object from the query
  • Confirm that the web_history objects from both queries were the same WebEnv (if not, error)
  • Get the QueryKey from both web_history objects, and add a "#" in front of them and parentheses around them.
  • Add the correct boolean operator in front of (for NOT) or between (for AND and OR) the queries with parentheses around the history QueryKey.
  • Do the search
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant