Skip to content

Commit 85ca704

Browse files
committed
vevtorized most worms_* fxns
1 parent 2e1a2d5 commit 85ca704

18 files changed

+111
-64
lines changed

R/worms_children.R

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1-
#' Children search
1+
#' Children search of WoRMS data.
2+
#'
23
#' @export
34
#' @template worms_id
45
#' @param offset Starting record number, when retrieving next chunk of (50) records. Default=1.
56
#' @param marine_only (logical) Include results from marine taxa only. Default: TRUE.
67
#' @examples \dontrun{
78
#' worms_children(ids=106135)
9+
#' worms_children(ids=c(106135,159283))
10+
#' out <- worms_children(ids=c(106135,159283))
11+
#' head(out)
812
#' }
913
worms_children <- function(ids=NULL, offset=NULL, marine_only=1, opts=NULL, iface=NULL, ...)
1014
{
1115
server <- 'http://www.marinespecies.org/aphia.php?p=soap'
12-
upiface <- worms_update_iface(update_iface)
13-
if(!is.null(upiface)) worms_iface <- iface
16+
if(!is.null(iface)) worms_iface <- iface
1417
fxn <- worms_get_fxn('getAphiaChildrenByID')
15-
res <- fxn(AphiaID = ids, offset = offset, marine_only = marine_only, server = server, .opts = opts)
16-
do.call(rbind, lapply(res, function(y) data.frame(unclass(y), stringsAsFactors = FALSE)))
17-
}
18+
res <- lapply(ids, fxn, offset = offset, marine_only = marine_only, server = server, .opts = opts)
19+
parse_data(res)
20+
}
21+
22+
# #' @method print worms
23+
# #' @export
24+
# #' @rdname worms
25+
# print.worms <- function(x, ...){
26+
# if(!is(x, "worms")) stop('Input must be of class worms')
27+
# print(x[ , !names(x) %in% c('url','citation') ])
28+
# }

R/worms_common.R

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
#' Common names from ID
1+
#' Common names from WoRMS ID
2+
#'
23
#' @export
34
#' @template worms_id
45
#' @examples \dontrun{
56
#' worms_common(ids=1080)
67
#' worms_common(ids=22388)
78
#' worms_common(ids=123080)
89
#' worms_common(ids=160281)
10+
#' worms_common(ids=c(1080,22388,160281,123080,22388))
911
#' }
1012
worms_common <- function(ids=NULL, opts=NULL, iface=NULL, ...)
1113
{
1214
server <- 'http://www.marinespecies.org/aphia.php?p=soap'
13-
upiface <- worms_update_iface(update_iface)
14-
if(!is.null(upiface)) worms_iface <- iface
15+
if(!is.null(iface)) worms_iface <- iface
1516
fxn <- worms_get_fxn('getAphiaVernacularsByID')
16-
res <- fxn(AphiaID = ids, server = server, .opts = opts)
17-
do.call(rbind, lapply(res, function(y) data.frame(unclass(y), stringsAsFactors = FALSE)))
18-
}
17+
res <- lapply(ids, fxn, server = server, .opts = opts)
18+
names(res) <- ids
19+
parse_data_byname(res)
20+
}

R/worms_hierarchy.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#' @template worms_id
44
#' @examples \dontrun{
55
#' worms_hierarchy(ids=733271)
6+
#' worms_hierarchy(ids=123080)
67
#' }
78
worms_hierarchy <- function(ids=NULL, opts=NULL, iface=NULL, ...)
89
{
910
server <- 'http://www.marinespecies.org/aphia.php?p=soap'
10-
upiface <- worms_update_iface(update_iface)
11-
if(!is.null(upiface)) worms_iface <- iface
11+
if(!is.null(iface)) worms_iface <- iface
1212
fxn <- worms_get_fxn('getAphiaClassificationByID')
1313
res <- fxn(AphiaID = ids, server = server, .opts = opts)
1414
df <- data.frame(aphiaid=res@AphiaID, rank=res@rank, scientificname=res@scientificname, stringsAsFactors = FALSE)

R/worms_name.R

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
#' Get name from a WORMS id
2+
#'
23
#' @export
34
#' @import SSOAP
45
#' @template worms_id
56
#' @examples \dontrun{
6-
#' worms_name(id=1080)
7+
#' worms_name(ids=1080)
8+
#' worms_name(ids=c(1080,22388,160281,123080,22388))
9+
#' worms_name(ids=c(1080,22388,160281,123080,22388,106135,159283))
710
#' }
8-
worms_name <- function(id=NULL, opts=NULL, iface=NULL, ...)
11+
worms_name <- function(ids=NULL, opts=NULL, iface=NULL, ...)
912
{
1013
server <- 'http://www.marinespecies.org/aphia.php?p=soap'
11-
upiface <- worms_update_iface(update_iface)
12-
if(!is.null(upiface)) worms_iface <- iface
14+
if(!is.null(iface)) worms_iface <- iface
1315
fxn <- worms_get_fxn('getAphiaNameByID')
14-
fxn(AphiaID = id, server = server, .opts = opts)
16+
vapply(ids, fxn, FUN.VALUE = character(1), server = server, .opts = opts)
1517
}

R/worms_records.R

+15-12
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@
2828
#' }
2929
#' @examples \dontrun{
3030
#' worms_records(scientific='Salmo')
31+
#' worms_records(scientific=c('Salmo','Aphanius'))
3132
#' worms_records(scientific='Liopsetta glacialis')
3233
#' worms_records(common='salmon')
34+
#' worms_records(common=c('salmon','char'))
3335
#' worms_records(startdate='2014-06-01T00:00:00', enddate='2014-06-02T00:00:00')
34-
#' worms_records(id=1080)
35-
#' worms_records(extid=6830, type='ncbi')
36+
#' worms_records(ids=1080)
37+
#' worms_records(extids=6830, type='ncbi')
3638
#' }
37-
worms_records <- function(scientific=NULL, common=NULL, id=NULL, extid=NULL, like=NULL, type=NULL,
39+
worms_records <- function(scientific=NULL, common=NULL, ids=NULL, extids=NULL, like=NULL, type=NULL,
3840
marine_only=1, offset=NULL, startdate=NULL, enddate=NULL, opts=NULL, iface=NULL, ...)
3941
{
4042
server <- 'http://www.marinespecies.org/aphia.php?p=soap'
@@ -43,21 +45,22 @@ worms_records <- function(scientific=NULL, common=NULL, id=NULL, extid=NULL, lik
4345
'getAphiaRecordsByVernacular'
4446
} else if (!is.null(startdate)|!is.null(enddate)) {
4547
'getAphiaRecordsByDate'
46-
} else if(!is.null(extid)) {
48+
} else if(!is.null(extids)) {
4749
'getAphiaRecordByExtID'
48-
} else if(!is.null(id)){
50+
} else if(!is.null(ids)){
4951
'getAphiaRecordByID'
5052
} else {
5153
if(length(scientific) > 1) 'getAphiaRecordsByNames' else 'getAphiaRecords'
5254
}
5355
fxn <- worms_get_fxn(endpt)
5456
res <- switch(endpt,
55-
getAphiaRecords = fxn(scientificname = scientific, like = like, fuzzy = 'false', marine_only = marine_only, offset = 'false', server = server, .opts = opts, ...),
56-
getAphiaRecordsByNames = fxn(scientificname = scientific, like = like, fuzzy = 'false', marine_only = marine_only, server = server, .opts = opts, ...),
57-
getAphiaRecordsByVernacular = fxn(vernacular = common, like = like, offset = offset, server = server, .opts = opts, ...),
58-
getAphiaRecordsByDate = fxn(startdate = startdate, enddate = enddate, marine_only = marine_only, offset = offset, server = server, .opts = opts, ...),
59-
getAphiaRecordByID = fxn(AphiaID = id, server = server, .opts = opts, ...),
60-
getAphiaRecordByExtID = fxn(id = extid, type = type, server = server, .opts = opts, ...)
57+
getAphiaRecords = lapply(scientific, fxn, like = like, fuzzy = 'false', marine_only = marine_only, offset = 'false', server = server, .opts = opts, ...),
58+
getAphiaRecordsByNames = lapply(scientific, fxn, like = like, fuzzy = 'false', marine_only = marine_only, server = server, .opts = opts, ...),
59+
getAphiaRecordsByVernacular = lapply(common, fxn, like = like, offset = offset, server = server, .opts = opts, ...),
60+
getAphiaRecordsByDate = lapply(startdate, fxn, enddate = enddate, marine_only = marine_only, offset = offset, server = server, .opts = opts, ...),
61+
getAphiaRecordByID = lapply(ids, fxn, server = server, .opts = opts, ...),
62+
getAphiaRecordByExtID = lapply(extids, fxn, type = type, server = server, .opts = opts, ...)
6163
)
62-
do.call(rbind, lapply(res, function(y) data.frame(unclass(y), stringsAsFactors = FALSE)))
64+
names(res) <- switch(endpt, getAphiaRecords=scientific, getAphiaRecordsByNames=scientific, getAphiaRecordsByVernacular=common, getAphiaRecordsByDate=startdate, getAphiaRecordByID=ids, getAphiaRecordByExtID=extids)
65+
parse_data_byname(res)
6366
}

R/worms_sources.R

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
#' @examples \dontrun{
55
#' worms_sources(ids=1080)
66
#' worms_sources(ids=278241)
7+
#' worms_sources(ids=c(1080,278241))
78
#' }
89
worms_sources <- function(ids=NULL, opts=NULL, iface=NULL, ...)
910
{
1011
server <- 'http://www.marinespecies.org/aphia.php?p=soap'
11-
upiface <- worms_update_iface(update_iface)
12-
if(!is.null(upiface)) worms_iface <- iface
12+
if(!is.null(iface)) worms_iface <- iface
1313
fxn <- worms_get_fxn('getSourcesByAphiaID')
14-
res <- fxn(AphiaID = ids, server = server, .opts = opts)
15-
do.call(rbind, lapply(res, function(y) data.frame(unclass(y), stringsAsFactors = FALSE)))
14+
res <- lapply(ids, fxn, server = server, .opts = opts)
15+
names(res) <- ids
16+
parse_data_byname(res)
17+
# do.call(rbind, lapply(res, function(y) data.frame(unclass(y), stringsAsFactors = FALSE)))
1618
}

R/worms_synonyms.R

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#' Synonyms search
1+
#' Synonyms search of WoRMS data.
22
#'
33
#' @export
44
#' @template worms_id
@@ -12,10 +12,5 @@ worms_synonyms <- function(ids=NULL, opts=NULL, iface=NULL, ...)
1212
if(!is.null(iface)) worms_iface <- iface
1313
fxn <- worms_get_fxn('getAphiaSynonymsByID')
1414
res <- lapply(ids, fxn, server = server, .opts = opts)
15-
do.call(rbind, lapply(res, function(y) if(length(y)==1){
16-
data.frame(inputid=y[[1]]$AphiaID, unclass(y[[1]]), stringsAsFactors = FALSE)
17-
} else {
18-
do.call(rbind, lapply(y, function(z) data.frame(inputid=y[[1]]$AphiaID, unclass(z), stringsAsFactors = FALSE)))
19-
}
20-
))
15+
parse_data(res)
2116
}

R/worms_utils.R

+21
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,24 @@ get_uri <- function(x, y){
5555
lsid=NA,
5656
)
5757
}
58+
59+
parse_data <- function(x){
60+
do.call(rbind, lapply(x, function(y) if(length(y)==1){
61+
data.frame(inputid=y[[1]]$AphiaID, unclass(y[[1]]), stringsAsFactors = FALSE)
62+
} else {
63+
do.call(rbind, lapply(y, function(z) data.frame(inputid=y[[1]]$AphiaID, unclass(z), stringsAsFactors = FALSE)))
64+
}
65+
))
66+
}
67+
68+
parse_data_byname <- function(x){
69+
tt <- list()
70+
for(i in seq_along(x)){
71+
if(length(x[[i]])==1){
72+
tt[[i]] <- data.frame(inputid=names(x)[i], unclass(x[[i]][[1]]), stringsAsFactors = FALSE)
73+
} else {
74+
tt[[i]] <- do.call(rbind, lapply(x[[i]], function(z) data.frame(inputid=names(x)[i], unclass(z), stringsAsFactors = FALSE)))
75+
}
76+
}
77+
do.call(rbind, tt)
78+
}

data/worms_iface.RData

1 Byte
Binary file not shown.

man-roxygen/worms_id.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#' @param id (numeric) One or more worms AphidID for a taxon.
1+
#' @param ids (numeric) One or more WoRMS AphidID's for a taxon.
22
#' @param opts (character) a named list of elements that are passed to the curlPerform function
33
#' which actually invokes the SOAP method. These options control aspects of the HTTP request,
44
#' including debugging information that is displayed on the console,

man/worms_children.Rd

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
% Generated by roxygen2 (4.0.1): do not edit by hand
22
\name{worms_children}
33
\alias{worms_children}
4-
\title{Children search}
4+
\title{Children search of WoRMS data.}
55
\usage{
66
worms_children(ids = NULL, offset = NULL, marine_only = 1, opts = NULL,
77
iface = NULL, ...)
88
}
99
\arguments{
10-
\item{id}{(numeric) One or more worms AphidID for a taxon.}
10+
\item{ids}{(numeric) One or more WoRMS AphidID's for a taxon.}
1111
1212
\item{opts}{(character) a named list of elements that are passed to the curlPerform function
1313
which actually invokes the SOAP method. These options control aspects of the HTTP request,
@@ -25,11 +25,14 @@ then pass it into any \code{worms_*} function. in the \code{iface} parameter.}
2525
\item{marine_only}{(logical) Include results from marine taxa only. Default: TRUE.}
2626
}
2727
\description{
28-
Children search
28+
Children search of WoRMS data.
2929
}
3030
\examples{
3131
\dontrun{
3232
worms_children(ids=106135)
33+
worms_children(ids=c(106135,159283))
34+
out <- worms_children(ids=c(106135,159283))
35+
head(out)
3336
}
3437
}
3538

man/worms_common.Rd

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
% Generated by roxygen2 (4.0.1): do not edit by hand
22
\name{worms_common}
33
\alias{worms_common}
4-
\title{Common names from ID}
4+
\title{Common names from WoRMS ID}
55
\usage{
66
worms_common(ids = NULL, opts = NULL, iface = NULL, ...)
77
}
88
\arguments{
9-
\item{id}{(numeric) One or more worms AphidID for a taxon.}
9+
\item{ids}{(numeric) One or more WoRMS AphidID's for a taxon.}
1010
1111
\item{opts}{(character) a named list of elements that are passed to the curlPerform function
1212
which actually invokes the SOAP method. These options control aspects of the HTTP request,
@@ -20,14 +20,15 @@ then pass it into any \code{worms_*} function. in the \code{iface} parameter.}
2020
\item{...}{Further args passed on to \code{SSOAP::.SOAP}.}
2121
}
2222
\description{
23-
Common names from ID
23+
Common names from WoRMS ID
2424
}
2525
\examples{
2626
\dontrun{
2727
worms_common(ids=1080)
2828
worms_common(ids=22388)
2929
worms_common(ids=123080)
3030
worms_common(ids=160281)
31+
worms_common(ids=c(1080,22388,160281,123080,22388))
3132
}
3233
}
3334

man/worms_extid.Rd

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
worms_extid(ids = NULL, type = "ncbi", opts = NULL, iface = NULL, ...)
77
}
88
\arguments{
9-
\item{id}{(numeric) One or more worms AphidID for a taxon.}
9+
\item{ids}{(numeric) One or more WoRMS AphidID's for a taxon.}
1010
1111
\item{opts}{(character) a named list of elements that are passed to the curlPerform function
1212
which actually invokes the SOAP method. These options control aspects of the HTTP request,

man/worms_hierarchy.Rd

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
worms_hierarchy(ids = NULL, opts = NULL, iface = NULL, ...)
77
}
88
\arguments{
9-
\item{id}{(numeric) One or more worms AphidID for a taxon.}
9+
\item{ids}{(numeric) One or more WoRMS AphidID's for a taxon.}
1010
1111
\item{opts}{(character) a named list of elements that are passed to the curlPerform function
1212
which actually invokes the SOAP method. These options control aspects of the HTTP request,
@@ -25,6 +25,7 @@ Hierarchy search
2525
\examples{
2626
\dontrun{
2727
worms_hierarchy(ids=733271)
28+
worms_hierarchy(ids=123080)
2829
}
2930
}
3031

man/worms_name.Rd

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
\alias{worms_name}
44
\title{Get name from a WORMS id}
55
\usage{
6-
worms_name(id = NULL, opts = NULL, iface = NULL, ...)
6+
worms_name(ids = NULL, opts = NULL, iface = NULL, ...)
77
}
88
\arguments{
9-
\item{id}{(numeric) One or more worms AphidID for a taxon.}
9+
\item{ids}{(numeric) One or more WoRMS AphidID's for a taxon.}
1010
1111
\item{opts}{(character) a named list of elements that are passed to the curlPerform function
1212
which actually invokes the SOAP method. These options control aspects of the HTTP request,
@@ -24,7 +24,9 @@ Get name from a WORMS id
2424
}
2525
\examples{
2626
\dontrun{
27-
worms_name(id=1080)
27+
worms_name(ids=1080)
28+
worms_name(ids=c(1080,22388,160281,123080,22388))
29+
worms_name(ids=c(1080,22388,160281,123080,22388,106135,159283))
2830
}
2931
}
3032

man/worms_records.Rd

+9-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
\alias{worms_records}
44
\title{Get records by ID, scientific name, common name, date, worms id, or external id.}
55
\usage{
6-
worms_records(scientific = NULL, common = NULL, id = NULL, extid = NULL,
7-
like = NULL, type = NULL, marine_only = 1, offset = NULL,
8-
startdate = NULL, enddate = NULL, opts = NULL, iface = NULL, ...)
6+
worms_records(scientific = NULL, common = NULL, ids = NULL,
7+
extids = NULL, like = NULL, type = NULL, marine_only = 1,
8+
offset = NULL, startdate = NULL, enddate = NULL, opts = NULL,
9+
iface = NULL, ...)
910
}
1011
\arguments{
11-
\item{id}{(numeric) One or more worms AphidID for a taxon.}
12+
\item{ids}{(numeric) One or more WoRMS AphidID's for a taxon.}
1213
1314
\item{opts}{(character) a named list of elements that are passed to the curlPerform function
1415
which actually invokes the SOAP method. These options control aspects of the HTTP request,
@@ -63,11 +64,13 @@ Parameter \code{type} should be one of the following values:
6364
\examples{
6465
\dontrun{
6566
worms_records(scientific='Salmo')
67+
worms_records(scientific=c('Salmo','Aphanius'))
6668
worms_records(scientific='Liopsetta glacialis')
6769
worms_records(common='salmon')
70+
worms_records(common=c('salmon','char'))
6871
worms_records(startdate='2014-06-01T00:00:00', enddate='2014-06-02T00:00:00')
69-
worms_records(id=1080)
70-
worms_records(extid=6830, type='ncbi')
72+
worms_records(ids=1080)
73+
worms_records(extids=6830, type='ncbi')
7174
}
7275
}
7376

man/worms_sources.Rd

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
worms_sources(ids = NULL, opts = NULL, iface = NULL, ...)
77
}
88
\arguments{
9-
\item{id}{(numeric) One or more worms AphidID for a taxon.}
9+
\item{ids}{(numeric) One or more WoRMS AphidID's for a taxon.}
1010
1111
\item{opts}{(character) a named list of elements that are passed to the curlPerform function
1212
which actually invokes the SOAP method. These options control aspects of the HTTP request,
@@ -26,6 +26,7 @@ Get sources/references by ID
2626
\dontrun{
2727
worms_sources(ids=1080)
2828
worms_sources(ids=278241)
29+
worms_sources(ids=c(1080,278241))
2930
}
3031
}
3132

0 commit comments

Comments
 (0)