Skip to content

Commit

Permalink
Roxygenizing FLCore
Browse files Browse the repository at this point in the history
  • Loading branch information
iagomosqueira committed Jan 13, 2017
1 parent e4aee1e commit 6cbfef4
Show file tree
Hide file tree
Showing 60 changed files with 2,123 additions and 569 deletions.
5 changes: 5 additions & 0 deletions R/FLArray.R
Expand Up @@ -88,6 +88,7 @@ setMethod("quant<-", signature(object="FLArray", value='character'),
) # }}}

# [ {{{

#' Extract
#'
#' Extract or replace parts of an FLR Object
Expand All @@ -106,6 +107,10 @@ setMethod("quant<-", signature(object="FLArray", value='character'),
#' Classes that are derived from \code{FLlst} (for example, \code{FLStocks} and
#' \code{FLBiols}) can be subset in a similar way to ordinary list objects.
#'
#' '$' for the \code{FLPar} and \code{FLQuant} classes operate only along the first
#' dimension ('params' or 'quant'), and are provided to be used specially in
#' formulas.
#'
#' @name Extract
#' @rdname Extract
#' @aliases [,FLArray,ANY,ANY,ANY-method
Expand Down
4 changes: 4 additions & 0 deletions R/FLComp.R
Expand Up @@ -223,6 +223,8 @@ setMethod("units<-", signature(x="FLComp", value="list"),
) # }}}

# '[' {{{
#' @rdname Extract
#' @aliases [,FLComp,ANY,ANY,ANY-method
setMethod('[', signature(x='FLComp'),
function(x, i, j, k, l, m, n, ..., drop=FALSE) {

Expand Down Expand Up @@ -261,6 +263,8 @@ setMethod('[', signature(x='FLComp'),
) # }}}

# "[<-" {{{
#' @rdname Extract
#' @aliases [<-,FLComp,ANY,ANY,ANY-method
setMethod("[<-", signature(x="FLComp"),
function(x, i, j, k, l, m, n, ..., value="missing")
{
Expand Down
4 changes: 3 additions & 1 deletion R/FLI.R
Expand Up @@ -14,7 +14,9 @@ setMethod(computeCatch, signature("FLI"), function(object){
}) # }}}

# '[' {{{
setMethod('[', signature(x='FLI'),
#' @rdname Extract
#' @aliases [,FLI,ANY,ANY,ANY-method
setMethod('[', signature(x='FLI', i='ANY', j='ANY', drop='ANY'),
function(x, i, j, k, l, m, n, ..., drop=FALSE)
{
qnames <- names(getSlots(class(x))[getSlots(class(x))=="FLQuant"])
Expand Down
5 changes: 5 additions & 0 deletions R/FLIndexBiomass.R
Expand Up @@ -10,6 +10,9 @@
invisible(createFLAccesors("FLIndexBiomass", exclude=c('name', 'desc', 'range', 'effort'))) # }}}

# FLIndexBiomass() {{{

#' @rdname FLIndexBiomass
#' @aliases FLIndexBiomass,FLQuant-method
setMethod('FLIndexBiomass', signature(object='FLQuant'),
function(object, plusgroup=dims(object)$max, ...)
{
Expand Down Expand Up @@ -37,6 +40,8 @@ setMethod('FLIndexBiomass', signature(object='FLQuant'),
}
)

#' @rdname FLIndexBiomass
#' @aliases FLIndexBiomass,missing-method
setMethod('FLIndexBiomass', signature(object='missing'),
function(...)
{
Expand Down
12 changes: 10 additions & 2 deletions R/FLPar.R
Expand Up @@ -130,6 +130,8 @@ setMethod('FLPar', signature('FLPar'),
) # }}}

# '[' {{{
#' @rdname Extract
#' @aliases [,FLPar,ANY,ANY,ANY-method
setMethod('[', signature(x='FLPar'),
function(x, i, j, k, l, m, n, ..., drop=FALSE) {

Expand Down Expand Up @@ -168,13 +170,17 @@ setMethod('[', signature(x='FLPar'),
}
)

setMethod('[', signature(x='FLPar', i='array'),
function(x, i, ..., drop=FALSE) {
#' @rdname Extract
#' @aliases [,FLPar,array,missing,missing-method
setMethod('[', signature(x='FLPar', i='array', j='missing', drop='missing'),
function(x, i) {
return(x@.Data[i])
}
) # }}}

# "[<-" {{{
#' @rdname Extract
#' @aliases [<-,FLPar,ANY,ANY,ANY-method
setMethod("[<-", signature(x="FLPar", value="ANY"),
function(x, i, j, k, l, m, n, ..., value)
{
Expand Down Expand Up @@ -863,6 +869,8 @@ setMethod("model.frame", signature(formula="FLPar"),
) # }}}

# $ {{{
#' @rdname Extract
#' @aliases $,FLPar-method
setMethod('$', signature(x='FLPar'),
function(x, name) {
return(x[name,])
Expand Down
13 changes: 13 additions & 0 deletions R/FLQuant.R
Expand Up @@ -493,6 +493,9 @@ setMethod('yearTotals', signature(x='FLQuant'),
) # }}}

# sums {{{

#' @rdname dimSummaries
#' @aliases quantSums,FLQuant-method
setMethod('quantSums', signature(x='FLQuant'), function(x, na.rm=TRUE) {

res <- colSums(x, na.rm=na.rm)
Expand All @@ -509,18 +512,24 @@ setMethod('quantSums', signature(x='FLQuant'), function(x, na.rm=TRUE) {
quant=quant(x), units=units(x)))
})

#' @rdname dimSummaries
#' @aliases yearSums,FLQuant-method
setMethod('yearSums', signature(x='FLQuant'), function(x, na.rm=TRUE) {
return(apply(x,c(1,3,4,5,6), function(x, NA.RM=na.rm){
z <- x[!is.na(x)]; ifelse(length(z), sum(z, na.rm=NA.RM), NA)
}))
})

#' @rdname dimSummaries
#' @aliases unitSums,FLQuant-method
setMethod('unitSums', signature(x='FLQuant'), function(x, na.rm=TRUE) {
return(apply(x,c(1,2,4,5,6), function(x, NA.RM=na.rm){
z <- x[!is.na(x)]; ifelse(length(z), sum(z, na.rm=NA.RM), NA)
}))
})

#' @rdname dimSummaries
#' @aliases seasonSums,FLQuant-method
setMethod('seasonSums', signature(x='FLQuant'), function(x, na.rm=TRUE) {

# output, 1 season
Expand All @@ -541,6 +550,8 @@ setMethod('seasonSums', signature(x='FLQuant'), function(x, na.rm=TRUE) {
return(res)
})

#' @rdname dimSummaries
#' @aliases areaSums,FLQuant-method
setMethod('areaSums', signature(x='FLQuant'), function(x, na.rm=TRUE) {
return(apply(x,c(1,2,3,4,6), function(x, NA.RM=na.rm){
z <- x[!is.na(x)]; ifelse(length(z), sum(z, na.rm=NA.RM), NA)
Expand Down Expand Up @@ -1187,6 +1198,8 @@ setMethod("tsp", signature(x="FLQuant"),
) # }}}

# $ {{{
#' @rdname Extract
#' @aliases $,FLQuant-method
setMethod("$", signature(x="FLQuant"),
function(x, name) {
return(x[name,])
Expand Down
4 changes: 4 additions & 0 deletions R/FLQuantDistr.R
Expand Up @@ -199,6 +199,8 @@ setMethod("-",
) # }}}

## "[" {{{
#' @rdname Extract
#' @aliases [,FLQuantDistr,ANY,ANY,ANY-method
setMethod("[", signature(x="FLQuantDistr"),
function(x, i, j, k, l, m, n) {

Expand Down Expand Up @@ -227,6 +229,8 @@ setMethod("[", signature(x="FLQuantDistr"),
}
)

#' @rdname Extract
#' @aliases [,FLQuantDistr,array,missing,missing-method
setMethod("[", signature(x="FLQuantDistr", i="array", j="missing", drop="missing"),
function(x, i)
{
Expand Down
32 changes: 30 additions & 2 deletions R/FLSR.R
Expand Up @@ -17,7 +17,26 @@
#' formulation implemented for each of them.
#'
#' @name FLSR
#' @aliases FLSR-class FLSR FLSR-methods FLSR,ANY-method FLSR,missing-method
#' @aliases FLSR-class covar,FLSR-method desc,FLSR-method details,FLSR-method
#' distribution,FLSR-method fitted,FLSR-method gr,FLSR-method
#' hessian,FLSR-method initial,FLSR-method logl,FLSR-method
#' logLik,FLSR-method model,FLSR-method name,FLSR-method
#' params,FLSR-method range,FLSR-method rec,FLSR-method
#' residuals,FLSR-method ssb,FLSR-method vcov,FLSR-method
#' covar<-,FLSR,FLQuants-method desc<-,FLSR,character-method
#' details<-,FLSR,list-method distribution<-,FLSR,character-method
#' distribution<-,FLSR,factor-method fitted<-,FLSR,FLArray-method
#' fitted<-,FLSR,numeric-method gr<-,FLSR,function-method
#' hessian<-,FLSR,array-method initial<-,FLSR,function-method
#' logl<-,FLSR,function-method logLik<-,FLSR,logLik-method
#' logLik<-,FLSR,numeric-method model<-,FLSR,character-method
#' model<-,FLSR,formula-method model<-,FLSR,function-method
#' model<-,FLSR,list-method name<-,FLSR,character-method
#' params<-,FLSR,FLPar-method range<-,FLSR,numeric-method
#' rec<-,FLSR,FLQuant-method rec<-,FLSR,numeric-method
#' residuals<-,FLSR,FLArray-method residuals<-,FLSR,numeric-method
#' ssb<-,FLSR,FLQuant-method ssb<-,FLSR,numeric-method
#' vcov<-,FLSR,array-method
#' @docType class
#' @section Slots: \describe{
#' \item{name}{Name of the object (\code{character}).}
Expand Down Expand Up @@ -129,6 +148,8 @@ setClass('FLSR',
invisible(createFLAccesors("FLSR", include=c('rec', 'ssb', 'covar'))) # }}}

# FLSR() {{{
#' @rdname FLSR
#' @aliases FLSR,ANY-method
setMethod('FLSR', signature(model='ANY'),
function(model, ...)
{
Expand Down Expand Up @@ -164,6 +185,8 @@ setMethod('FLSR', signature(model='ANY'),
return(res)
}
)
#' @rdname FLSR
#' @aliases FLSR,missing-method
setMethod('FLSR', signature(model='missing'),
function(...)
return(FLSR(formula(NULL), ...))) # }}}
Expand Down Expand Up @@ -383,12 +406,15 @@ setClass("FLSRs", contains="FLComps",
}
)

# constructor
#' @rdname FLSRs
#' @aliases FLSRs,FLSR-method
setMethod("FLSRs", signature(object="FLSR"), function(object, ...) {
lst <- c(object, list(...))
FLSRs(lst)
})

#' @rdname FLSRs
#' @aliases FLSRs,missing-method
setMethod("FLSRs", signature(object="missing"),
function(...) {
# empty
Expand All @@ -404,6 +430,8 @@ setMethod("FLSRs", signature(object="missing"),
}
)

#' @rdname FLSRs
#' @aliases FLSRs,list-method
setMethod("FLSRs", signature(object="list"),
function(object, ...) {

Expand Down
11 changes: 10 additions & 1 deletion R/FLStock.R
Expand Up @@ -5,8 +5,9 @@
# Maintainer: Iago Mosqueira, EC JRC

# FLStock() {{{

#' @rdname FLStock
#' @aliases FLStock,FLQuant-method FLStock,missing-method
#' @aliases FLStock,FLQuant-method
setMethod('FLStock', signature(object='FLQuant'),
function(object, plusgroup=dims(object)$max, ...) {

Expand Down Expand Up @@ -42,6 +43,8 @@ setMethod('FLStock', signature(object='FLQuant'),
}
)

#' @rdname FLStock
#' @aliases FLStock,missing-method
setMethod('FLStock', signature(object='missing'),
function(...)
{
Expand Down Expand Up @@ -74,6 +77,8 @@ setMethod('FLStock', signature(object='missing'),
}
)

#' @rdname FLStock
#' @aliases FLStock,FLQuants-method
setMethod('FLStock', signature(object='FLQuants'),
function(object, ...)
{
Expand Down Expand Up @@ -473,6 +478,8 @@ setMethod("ssbpurec",signature(object="FLStock"),
)# }}}

# '[' {{{
#' @rdname Extract
#' @aliases [,FLStock,ANY,ANY,ANY-method
setMethod('[', signature(x='FLStock'),
function(x, i, j, k, l, m, n, ..., drop=FALSE)
{
Expand Down Expand Up @@ -517,6 +524,8 @@ setMethod('[', signature(x='FLStock'),
) # }}}

# "[<-" {{{
#' @rdname Extract
#' @aliases [<-,FLStock,ANY,ANY,FLStock-method
setMethod("[<-", signature(x="FLStock", value="FLStock"),
function(x, i, j, k, l, m, n, ..., value) {
if (missing(i))
Expand Down
26 changes: 17 additions & 9 deletions R/FLlst-methods.R
Expand Up @@ -12,6 +12,9 @@ setAs("NULL", "FLQuant", function(from) FLQuant())
# }}}

# replacement, [[<-, $, [<- {{{

#' @rdname Extract
#' @aliases [[<-,FLlst,ANY,missing,ANY-method
setReplaceMethod("[[", signature(x="FLlst", i="ANY", j="missing", value="ANY"),
function(x, i, j, value)
{
Expand All @@ -37,6 +40,8 @@ setReplaceMethod("[[", signature(x="FLlst", i="ANY", j="missing", value="ANY"),
}
)

#' @rdname Extract
#' @aliases $<-,FLlst,ANY-method
setReplaceMethod("$", signature(x="FLlst", value="ANY"),
function(x, name, value)
{
Expand Down Expand Up @@ -64,6 +69,8 @@ setReplaceMethod("$", signature(x="FLlst", value="ANY"),
stop("Invalid object, classes do not match.")
})

#' @rdname Extract
#' @aliases [<-,FLlst,ANY,missing,ANY-method
setReplaceMethod("[", signature(x="FLlst", i="ANY", j="missing", value="ANY"),
function(x, i, j, value)
{
Expand All @@ -87,15 +94,16 @@ setReplaceMethod("[", signature(x="FLlst", i="ANY", j="missing", value="ANY"),
}
) # }}}

# subset, [ {{{


setMethod("[", signature(x="FLlst", i="ANY", j="missing", drop="ANY"), function(x,i,j,drop){
lst <- as(x, "list")
# names dropped!
names(lst) <- names(x)
lst <- lst[i]
new(is(x), lst)
# [ {{{
#' @rdname Extract
#' @aliases [,FLlst,ANY,missing,ANY-method
setMethod("[", signature(x="FLlst", i="ANY", j="missing", drop="ANY"),
function(x,i,j,drop){
lst <- as(x, "list")
# names dropped!
names(lst) <- names(x)
lst <- lst[i]
new(is(x), lst)
}) # }}}

# lapply {{{
Expand Down

0 comments on commit 6cbfef4

Please sign in to comment.