-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from gjgetzinger/master
Also closes #196. Thank you for @gjgetzinger for your contribution! I think two separate topics were combined by accident, can you contact me at webchem at ropensci dot org so we can discuss why this could have happened? Thanks.
- Loading branch information
Showing
6 changed files
with
140 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ Authors@R: c(person("Eduard", "Szöcs", role = c("aut", "cre"), | |
person("Andreas", "Scharmüller", role = "ctb"), | ||
person("Eric R", "Scott", role = "ctb"), | ||
person("Jan", "Stanstrup", role = "ctb"), | ||
person("Gordon", "Getzinger", role = "ctb"), | ||
person("Tamás", "Stirling", role = "ctb")) | ||
Maintainer: Tamás Stirling <[email protected]> | ||
LazyLoad: yes | ||
|
@@ -36,4 +37,4 @@ Imports: | |
Suggests: | ||
testthat, | ||
rcdk | ||
RoxygenNote: 7.0.2 | ||
RoxygenNote: 6.1.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#' Get record details from U.S. EPA Substance Registry Servives (SRS) | ||
#' | ||
#' Get record details from SRS, see \url{https://cdxnodengn.epa.gov/cdx-srs-rest/} | ||
#' | ||
#'@param query character; query ID. | ||
#'@param from character; type of query ID, e.g. \code{'itn'} , \code{'cas'}, | ||
#' \code{'epaid'}, \code{'tsn'}, \code{'name'}. | ||
#' | ||
#'@return a list of lists (for each supplied query): a list of 22. subsKey, | ||
#' internalTrackingNumber, systematicName, epaIdentificationNumber, | ||
#' currentCasNumber, currentTaxonomicSerialNumber, epaName, substanceType, | ||
#' categoryClass, kingdomCode, iupacName, pubChemId, molecularWeight, | ||
#' molecularFormula, inchiNotation, smilesNotation, classifications, | ||
#' characteristics, synonyms, casNumbers, taxonomicSerialNumbers, relationships | ||
#'@author Gordon Getzinger, \email{gjg3@@duke.edu} | ||
#'@export | ||
#' | ||
#' @examples | ||
#' \donttest{ | ||
#' # might fail if API is not available | ||
#' srs_query(query = '50-00-0', from = 'cas') | ||
#' | ||
#' ### multiple inputs | ||
#' casrn <- c('50-00-0', '67-64-1') | ||
#' srs_query(query = casrn, from = 'cas') | ||
#' } | ||
srs_query <- | ||
function(query, | ||
from = c("itn", "cas", "epaid", "tsn", "name")) { | ||
entity_url <- "https://cdxnodengn.epa.gov/cdx-srs-rest/" | ||
|
||
rst <- lapply(query, function(x) { | ||
entity_query <- paste0(entity_url, "/substance/", from, "/", x) | ||
response <- httr::GET(entity_query) | ||
|
||
if (response$status_code == 200) { | ||
text_content <- httr::content(response, "text") | ||
if (text_content == "[]") { | ||
return(NA) | ||
} else { | ||
jsonlite::fromJSON(text_content) | ||
} | ||
} else { | ||
stop(httr::http_status(response)$message) | ||
} | ||
}) | ||
names(rst) <- query | ||
return(rst) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.