Skip to content

Commit

Permalink
completed matching functions to webservice
Browse files Browse the repository at this point in the history
  • Loading branch information
colinpmillar committed Sep 15, 2016
1 parent a0a332d commit d91e2ba
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 10 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ Suggests: knitr,
Imports: RCurl,
XML,
utils
Description: R interface to access the web services of the ICES (International
Description: R interface to access the RECO POX web services of the ICES (International
Council for the Exploration of the Sea) Vocabularies
database <http://vocab.ices.dk/services/RDF.aspx>.
database <http://vocab.ices.dk/services/POX.aspx>.
License: GPL (>= 2)
URL: http://vocab.ices.dk/services/RDF.aspx
URL: http://vocab.ices.dk/services/POX.aspx
RoxygenNote: 5.0.1
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Generated by roxygen2: do not edit by hand

export(getCodeDetail)
export(getCodeList)
export(getCodeTypeList)
importFrom(RCurl,basicTextGatherer)
importFrom(RCurl,curlPerform)
importFrom(XML,getChildrenStrings)
Expand Down
31 changes: 31 additions & 0 deletions R/getCodeDetail.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#' Get List of Details
#'
#' Retrieves all the details for the given code.
#'
#' @param code_type the code type, e.g. SpecWoRMS
#' @param code the code, e.g. 101170
#'
#' @return A data frame.
#'
#' @examples
#' # get the details for species code 101170
#' getCodeDetail("SpecWoRMS", "101170")
#'
#' @export
getCodeDetail <- function(code_type, code) {

# base url
url <- sprintf("http://vocab.ices.dk/services/pox/GetCodeDetail/%s/%s", code_type, code)

# read and parse XML from API
out <- curlVocab(url = url)
# parse the xml text string suppplied by the Datras webservice
# returning a dataframe
out <- parseVocab(out)

# for now, drop parent relation...
out <- out[names(out) != "ParentRelation"]

# return
out
}
16 changes: 14 additions & 2 deletions R/getAphiaID.R → R/getCodeList.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,29 @@
#'
#' Retrieves all the codes for the given code type.
#'
#' @param code_type the code type, e.g. SpecWoRMS
#' @param date restrict output to codes
#' modified after the given date.
#' date should be text and in the fomat "yyyy-mm-dd", e.g. "2010-12-01"
#'
#' @return A data frame.
#'
#' @examples
#' # get the WoRMS AphiaIDs for ICES assessment species
#' getCodeList("SpecWoRMS")
#'
#' @export
getCodeList <- function(code_type) {
getCodeList <- function(code_type, date=NULL) {

# read and parse XML from API
# base url
url <- sprintf("http://vocab.ices.dk/services/pox/GetCodeList/%s", code_type)

# if date supplied return list of codes modified after the given date
if (!is.null(date)) {
url <- sprintf(paste0(url, "/%s"), date)
}

# read and parse XML from API
out <- curlVocab(url = url)
# parse the xml text string suppplied by the Datras webservice
# returning a dataframe
Expand Down
34 changes: 34 additions & 0 deletions R/getCodeTypeList.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#' Get List of Code Types
#'
#' Retrieves all the codes types.
#'
#' @param date restrict output to code types
#' modified after the given date.
#' date should be text and in the fomat "yyyy-mm-dd", e.g. "2010-12-01"
#'
#' @return A data frame.
#'
#' @examples
#' codes <- getCodeTypeList()
#' codes[grep("worms", tolower(codes$Description)),]
#'
#' @export
getCodeTypeList <- function(date=NULL) {

# base url
url <- "http://vocab.ices.dk/services/pox/GetCodeTypeList"

# if date supplied return list of code types modified after the given date
if (!is.null(date)) {
url <- sprintf(paste0(url, "/%s"), date)
}

# read and parse XML from API
out <- curlVocab(url = url)
# parse the xml text string suppplied by the Datras webservice
# returning a dataframe
out <- parseVocab(out)

# return
out
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
icesVocab
======

icesVocab implements R functions that access the [web services](http://vocab.ices.dk/services/RDF.aspx) of the [ICES (International Council for the Exploration of the Sea)](http://www.ices.dk/Pages/default.aspx) [Vocabularies](http://vocab.ices.dk/).
icesVocab implements R functions that access the [RECO POX web services](http://vocab.ices.dk/services/POX.aspx) of the [ICES (International Council for the Exploration of the Sea)](http://www.ices.dk/Pages/default.aspx) [Vocabularies](http://vocab.ices.dk/).

icesVocab is implemented as an [R](https://www.r-project.org) package and available on [GitHub](https://cran.r-project.org/package=icesVocab).

Expand All @@ -36,9 +36,9 @@ library(icesVocab)
References
----------

ICES Vocab web services:
ICES Vocabularies RECO POX web services:

[http://vocab.ices.dk/services/RDF.aspx](http://vocab.ices.dk/services/RDF.aspx).
[http://vocab.ices.dk/services/POX.aspx](http://vocab.ices.dk/services/POX.aspx).

ICES Vocab:

Expand Down
25 changes: 25 additions & 0 deletions man/getCodeDetail.Rd

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

11 changes: 9 additions & 2 deletions man/getCodeList.Rd

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

25 changes: 25 additions & 0 deletions man/getCodeTypeList.Rd

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

0 comments on commit d91e2ba

Please sign in to comment.