Skip to content

Commit

Permalink
version 1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
bgcarlisle authored and cran-robot committed Mar 6, 2024
1 parent b22323f commit b015034
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 31 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
@@ -1,6 +1,6 @@
Package: pubmedtk
Title: 'Pubmed' Toolkit
Version: 1.0.3
Version: 1.0.4
Authors@R:
person("Benjamin Gregory", "Carlisle", , "murph@bgcarlisle.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-8975-0649"))
Expand All @@ -13,13 +13,13 @@ BugReports: https://github.com/bgcarlisle/pubmedtk/issues
Imports: magrittr, dplyr, xml2, jsonlite, httr, assertthat, stringr,
rlang, utils
Encoding: UTF-8
RoxygenNote: 7.3.0
RoxygenNote: 7.3.1
Suggests: testthat (>= 3.0.0)
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2024-02-27 21:32:56 UTC; researchfairy
Packaged: 2024-03-05 21:30:14 UTC; researchfairy
Author: Benjamin Gregory Carlisle [aut, cre]
(<https://orcid.org/0000-0001-8975-0649>)
Maintainer: Benjamin Gregory Carlisle <murph@bgcarlisle.com>
Repository: CRAN
Date/Publication: 2024-02-27 22:10:02 UTC
Date/Publication: 2024-03-05 21:50:02 UTC
10 changes: 5 additions & 5 deletions MD5
@@ -1,16 +1,16 @@
d74039c1b79d5a9ebc39043948578b39 *DESCRIPTION
ea884b89843afc9f048a3d904aa16079 *DESCRIPTION
8a026120dcc725392c4ee42947836dd7 *NAMESPACE
bb1137b7e7fa08d2a4a5c3f2629dc6a5 *NEWS.md
76ef1a53de3be22b96662f6a186e8bb4 *NEWS.md
8955382c87b4259347a9795e96374e1b *R/get_metadata_from_one_pmid.R
b336b3373ca3defbd504ef1f26c4374b *R/get_metadata_from_pmids.R
5a94e597d6070fc87d68b74da0af20e8 *R/get_pmids_from_one_search.R
c41f5b9a4dde11446b51ed075b602da8 *R/get_pmids_from_searches.R
cb39efb5cfaab813d5cc28fdccb08820 *R/intersection_check.R
d663220941beeed2b85d1552957e933c *R/get_pmids_from_searches.R
2cd33a1c07e9fb86ed9febdc4bee1f2e *R/intersection_check.R
13052b679e6fc07acd9354dd425f66c1 *R/pubmedtk-package.R
3031a6da4184e2ef0d70326a322b6db7 *README.md
ce08ae537b3af2b74c4232625e08bb0d *man/get_metadata_from_one_pmid.Rd
942fa522c3d35d12cfa4a463c87aec18 *man/get_metadata_from_pmids.Rd
63d138c944ce4e2967767118f5366533 *man/get_pmids_from_one_search.Rd
18b91fb07d0d397a18b66514884b6078 *man/get_pmids_from_searches.Rd
ae2567cfe18b0fcbd3dca90d0ca183d4 *man/intersection_check.Rd
70a10406be28c11975a79c1d2547904f *man/intersection_check.Rd
d710b8f21360c200f05eb3a276d2f4f8 *man/pubmedtk-package.Rd
13 changes: 13 additions & 0 deletions NEWS.md
@@ -1,8 +1,21 @@
# pubmedtk 1.0.4

* Fixed bug in `intersection_check()` where it would crash if the
column supplied was not named "pmid"
* Fixed bug in `get_pmids_from_searches()` where an NA search can
cause unexpected results
* Added `quiet` option to `intersection_check()` to disable progress
messages during download

---

# pubmedtk 1.0.3

* Added `$abstract` download to `get_metadata_from_one_pmid()` and
corresponding column to `get_metadata_from_pmids()`

---

# pubmedtk 1.0.2

* Added optional progress feedback during download for
Expand Down
26 changes: 18 additions & 8 deletions R/get_pmids_from_searches.R
Expand Up @@ -131,18 +131,28 @@ get_pmids_from_searches <- function (

for (query in queries) {

## Perform search
pm_search_result <- get_pmids_from_one_search(
query,
api_key
)
## Error checking
if (! is.na(query)) {
## Perform search
pm_search_result <- get_pmids_from_one_search(
query,
api_key
)
} else {

pm_search_result <- list(
pubmed_search_success = FALSE,
n_results = 0,
pmids = NA
)
}

## Apply it to the data frame

df <- df %>%
dplyr::mutate(
pubmed_search_success = ifelse(
!!dplyr::sym(column) == query,
! is.na (query) & !!dplyr::sym(column) == query,
pm_search_result$pubmed_search_success,
.data$pubmed_search_success
)
Expand All @@ -151,7 +161,7 @@ get_pmids_from_searches <- function (
df <- df %>%
dplyr::mutate(
n_results = ifelse(
!!dplyr::sym(column) == query,
! is.na(query) & !!dplyr::sym(column) == query,
pm_search_result$n_results,
.data$n_results
)
Expand All @@ -160,7 +170,7 @@ get_pmids_from_searches <- function (
df <- df %>%
dplyr::mutate(
pmids = ifelse(
!!dplyr::sym(column) == query,
! is.na(query) & !!dplyr::sym(column) == query,
ifelse(
! is.na(pm_search_result$pmids),
jsonlite::toJSON(pm_search_result$pmids),
Expand Down
35 changes: 22 additions & 13 deletions R/intersection_check.R
Expand Up @@ -10,6 +10,9 @@
#'
#' @param api_key A valid Pubmed API key
#'
#' @param quiet A boolean TRUE or FALSE. If TRUE, no progress messages
#' will be printed during download. FALSE by default.
#'
#' @param batch_size An integer greater than 0 and less than 10000
#'
#' @return A data frame containing the original columns, as well as
Expand Down Expand Up @@ -60,7 +63,8 @@ intersection_check <- function (
column,
query,
api_key,
batch_size = 1000
batch_size = 1000,
quiet = FALSE
) {

out <- tryCatch({
Expand Down Expand Up @@ -135,7 +139,9 @@ intersection_check <- function (
dplyr::slice_head() %>%
dplyr::select(!!dplyr::sym(column))

message(paste(nrow(pmids), "unique PMID's to check"))
if (! quiet) {
message(paste(nrow(pmids), "unique PMID's to check"))
}

## Add new columns
pmids$pm_checked <- FALSE
Expand All @@ -147,7 +153,8 @@ intersection_check <- function (
dplyr::filter(! .data$pm_checked) %>%
utils::head(n=batch_size)

pmid_search_term <- pmid_batch$pmid %>%
pmid_search_term <- pmid_batch %>%
dplyr::pull(!!dplyr::sym(column)) %>%
paste(collapse="[PMID] OR ") %>%
paste0("[PMID]")

Expand Down Expand Up @@ -185,22 +192,22 @@ intersection_check <- function (
pmids <- pmids %>%
dplyr::mutate(
pm_checked = ifelse(
.data$pmid %in% pmid_batch$pmid,
!!dplyr::sym(column) %in% dplyr::pull(pmid_batch, !!dplyr::sym(column)),
TRUE,
.data$pm_checked
)
) %>%
dplyr::mutate(
found_in_pm_query = ifelse(
.data$pmid %in% found_pmids,
!!dplyr::sym(column) %in% found_pmids,
TRUE,
.data$found_in_pm_query
)
) %>%
dplyr::mutate(
found_in_pm_query = ifelse(
.data$pmid %in% pmid_batch$pmid &
! .data$pmid %in% found_pmids,
!!dplyr::sym(column) %in% dplyr::pull(pmid_batch, !!dplyr::sym(column)) &
! (!!dplyr::sym(column) %in% found_pmids),
FALSE,
.data$found_in_pm_query
)
Expand All @@ -211,13 +218,15 @@ intersection_check <- function (
nrow()

prop_done <- round(100 * n_done / nrow(pmids), digits=3)

message(
paste0(
prop_done,
"% done"

if (! quiet) {
message(
paste0(
prop_done,
"% done"
)
)
)
}
}

out <- df %>%
Expand Down
12 changes: 11 additions & 1 deletion man/intersection_check.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b015034

Please sign in to comment.