Skip to content

Commit

Permalink
address cmd notes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Timm committed Apr 10, 2024
1 parent 9fee904 commit 90ec6a7
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 6 deletions.
4 changes: 4 additions & 0 deletions R/data_pmc_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ data_pmc_list <- function(force_install = FALSE) {
# Local file path for storing the processed data
df <- file.path(rappdirs::user_data_dir('pubmedr'), 'oa_file_list.rds')

# Define PMID and PMCID variables
PMID <- NULL
PMCID <- NULL

# Check if the file exists, and download and process it if it doesn't or if forced
if (!file.exists(df) | force_install) {
# Create the directory if it doesn't exist
Expand Down
2 changes: 2 additions & 0 deletions R/get_records.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
#' @importFrom pbapply pblapply
#' @importFrom data.table rbindlist
#' @examples
#' \donttest{
#' pmids <- c("38136652", "31345328", "32496629")
#' results <- get_records(pmids, endpoint = "pubmed_abstracts", cores = 1)
#' }
#' @export
#' @rdname get_records
#'
Expand Down
11 changes: 10 additions & 1 deletion R/search_pubmed.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@
#' @importFrom rentrez entrez_search
#' @export
#' @examples
#' \donttest{
#' ethnob1 <- search_pubmed("ethnobotany", 2010, 2012)
#' ethnob2 <- search_pubmed("ethnobotany", use_pub_years = FALSE)
search_pubmed <- function(x, start_year = NULL, end_year = NULL, retmax = 9999, use_pub_years = TRUE) {
#' }
#'
#'
search_pubmed <- function(x,
start_year = NULL,
end_year = NULL,
retmax = 9999,
use_pub_years = TRUE) {

if(!is.character(x) || length(x) != 1) {
stop("x must be a single character string.")
}
Expand Down
13 changes: 9 additions & 4 deletions R/source_icites.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
data.table::setDT(pmiddf)

# Clean and format the 'ref_count' column
ref_count <- NULL
pmiddf[, ref_count := ifelse(is.null(references)|is.na(references), NULL, references)]

# Process 'references' and 'cited_by' columns, handling empty or NA values
Expand All @@ -65,13 +66,16 @@
rs <- strsplit(pmiddf$ref_count, split = " ")

# Build a data frame for references
refs <- data.frame(doc_id = rep(gots, sapply(references, length)),
from = rep(gots, sapply(references, length)),
to = unlist(references))
doc_id <- NULL
from <- NULL
refs <- data.table::data.table(doc_id = rep(gots, sapply(references, length)),
from = rep(gots, sapply(references, length)),
to = unlist(references))
# Replace placeholder '99' with NA
refs[refs == 99] <- NA

# Aggregate reference data and convert to a data.table
refs0 <- data.table::setDT(refs)[, list(references = .N), by = .(from)]
refs0 <- refs[, list(references = .N), by = list(from)]

# Build a data frame for cited_by data
cited <- data.frame(doc_id = rep(gots, sapply(cited_by, length)),
Expand All @@ -86,6 +90,7 @@
f2 <- data.table::setDT(f1)[, list(references = list(.SD)), by = doc_id]

# Add citation network data to pmiddf
citation_net <- NULL
pmiddf[, citation_net := f2$references]
# Calculate and add reference count
pmiddf[, ref_count := sapply(rs, length)]
Expand Down
2 changes: 2 additions & 0 deletions R/source_pubmed.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
content.name = 'varx')

# Reshape the data into a wide format using data.table
id <- NULL
sum1 <- data.table::dcast(data = sum0,
formula = id ~ attribute,
value.var = 'varx')
Expand All @@ -39,6 +40,7 @@
sum1 <- sum1[, c('pmid', 'year', 'journal', 'articletitle', 'abstract')]

# Add annotations to the data table
annotations <- NULL
sum1[, annotations := list(lapply(parsed_records, '[[', 2))]

# Ensure proper encoding for compatibility
Expand Down
3 changes: 3 additions & 0 deletions R/source_pubtations.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
jj0$locations <- gsub("[^[:digit:],]", "", jj0$locations)

# Extract start and end positions of annotations
start <- NULL
end <- NULL
locations <- NULL
jj0[, c('start', 'length') := data.table::tstrsplit(locations, ",", fixed=TRUE)]
jj0[, start := as.integer(start)]
jj0[, end := start + as.integer(length)]
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ always_allow_html: true

# puremoe

## **P**ubMed **U**niform **Re**trieval for **M**ulti-**O**utput **E**xploration (puremoe)
> **P**ubMed **U**niform **RE**trieval for **M**ulti-**O**utput **E**xploration
An R package that provides a single interface for accessing a range of NLM/PubMed databases, including [PubMed](https://pubmed.ncbi.nlm.nih.gov/) abstract records, [iCite](https://icite.od.nih.gov/) bibliometric data, [PubTator](https://www.ncbi.nlm.nih.gov/research/pubtator/) named entity annotations, and full-text entries from [PubMed Central](https://www.ncbi.nlm.nih.gov/pmc/) (PMC). This unified interface simplifies the data retrieval process, allowing users to interact with multiple PubMed services/APIs/output formats through a single R function.

Expand Down

0 comments on commit 90ec6a7

Please sign in to comment.