ropensci / rentrez

talk with NCBI entrez using R
https://docs.ropensci.org/rentrez
Other
194 stars 38 forks source link

Feature Request: use_history in entrez_search becomes web_history #166

Open billdenney opened 3 years ago

billdenney commented 3 years ago

I learned a bit more about web_history earlier tonight, and I learned how to use it in #163. As I was thinking about the argument, I think it would be more helpful if instead of use_history, the argument was web_history, and it would take a web_history object (or something containing a web_history) and use that instead of creating a new web_history.

What works now is:

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)

What I'm hoping could work with this feature request is replaces the last 4 lines with:

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

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, web_history=q1)

The differences are:

This would also suggest that an as_web_history() generic function that would extract the web_history from any object containing a web_history object would be helpful to make this work more smoothly.