Skip to content

Commit

Permalink
added early return functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Jermiah committed Oct 4, 2023
1 parent 634db68 commit c8b7054
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions R/getPubChem.R
Original file line number Diff line number Diff line change
Expand Up @@ -684,10 +684,20 @@ getPubChemSubstance <- function(ids, from='cid', to='sids', ...,
#' @importFrom data.table data.table as.data.table merge.data.table last rbindlist fwrite
#' @importFrom BiocParallel bpparam bpworkers bpprogressbar bptry
#' @export
getPubChemAnnotations <- function(header='Available', type='Compound',
parseFUN=identity, ..., output='JSON', raw=FALSE,
getPubChemAnnotations <-
function(
header='Available',
type='Compound',
parseFUN=identity,
output='JSON',
raw=FALSE,
rawAnnotationDT=FALSE,
verbose = FALSE,
url='https://pubchem.ncbi.nlm.nih.gov/rest/pug_view/annotations/heading',
BPPARAM=bpparam(), proxy=FALSE) {
BPPARAM=bpparam(),
proxy=FALSE,
...
) {
funContext <- .funContext('::getPubChemAnnotations')
if (header == 'Available') {
queryURL <-
Expand Down Expand Up @@ -787,7 +797,7 @@ getPubChemAnnotations <- function(header='Available', type='Compound',
annotationDT <- rbindlist(pageList, fill=TRUE, use.names=TRUE)
annotationDT[, Data := lapply(Data, as.data.table)]
}

if (isTRUE(rawAnnotationDT)) return(annotationDT)
# parse the results to a user friendly format
switch(header,
'ATC Code'=return(.parseATCannotations(annotationDT)),
Expand Down Expand Up @@ -822,10 +832,12 @@ getPubChemAnnotations <- function(header='Available', type='Compound',
annotationDT <- merge.data.table(
dataDT[, .(SourceID, ATC_code)],
DT[, .(SourceName, SourceID, LinkedRecords)],
by='SourceID'
by='SourceID',
allow.cartesian=TRUE
)
DT <- annotationDT[, .(CID=unlist(LinkedRecords)),
by=.(SourceName, SourceID, ATC_code)]
DT <- unique(DT)
return(DT)
}

Expand Down

0 comments on commit c8b7054

Please sign in to comment.