Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
improved documentation
replace x by object if possible
  • Loading branch information
walke committed Oct 2, 2019
1 parent bd76bf9 commit ac4709d
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 87 deletions.
30 changes: 15 additions & 15 deletions R/AllGeneric.R
@@ -1,33 +1,33 @@
# Rainer Walke, MPIDR Rostock

setGeneric("header", function(x) standardGeneric("header"))
setGeneric("header", function(object) standardGeneric("header"))

setGeneric("footer", function(x) standardGeneric("footer"))
setGeneric("footer", function(object) standardGeneric("footer"))

setGeneric("lt1", function(x) standardGeneric("lt1"))
setGeneric("lt1", function(object) standardGeneric("lt1"))

setGeneric("content", function(x) standardGeneric("content"))
setGeneric("content", function(object) standardGeneric("content"))

setGeneric("country", function(x) standardGeneric("country"))
setGeneric("country", function(object) standardGeneric("country"))

setGeneric("protocol", function(x) standardGeneric("protocol"))
setGeneric("protocol", function(object) standardGeneric("protocol"))

setGeneric("lt1<-", function(x, value) standardGeneric("lt1<-"))
setGeneric("lt1<-", function(object, value) standardGeneric("lt1<-"))

setGeneric("selectYears", function(x, selectYears) standardGeneric("selectYears"))
setGeneric("selectYears", function(object, selectYears) standardGeneric("selectYears"))

setGeneric("ex1", function(x) standardGeneric("ex1"))
setGeneric("ex1", function(object) standardGeneric("ex1"))

setGeneric("ex1<-", function(x, value) standardGeneric("ex1<-"))
setGeneric("ex1<-", function(object, value) standardGeneric("ex1<-"))


setGeneric("rd1", function(x) standardGeneric("rd1"))
setGeneric("rd1", function(object) standardGeneric("rd1"))

setGeneric("rd1<-", function(x, value) standardGeneric("rd1<-"))
setGeneric("rd1<-", function(object, value) standardGeneric("rd1<-"))

setGeneric("selectRegion", function(x, selectRegion) standardGeneric("selectRegion"))
setGeneric("selectRegion", function(object, selectRegion) standardGeneric("selectRegion"))

setGeneric("re1", function(x) standardGeneric("re1"))
setGeneric("re1", function(object) standardGeneric("re1"))

setGeneric("re1<-", function(x, value) standardGeneric("re1<-"))
setGeneric("re1<-", function(object, value) standardGeneric("re1<-"))

52 changes: 26 additions & 26 deletions R/GENESISClasses.R
Expand Up @@ -22,22 +22,22 @@ setClass("RD1",

# slot getters
#' @export
setMethod("header", "RD1", function(x) x@header)
setMethod("header", "RD1", function(object) object@header)
#' @export
setMethod("footer", "RD1", function(x) x@footer)
setMethod("footer", "RD1", function(object) object@footer)
#' @export
setMethod("rd1", "RD1", function(x) x@rd1)
setMethod("rd1", "RD1", function(object) object@rd1)

#' @export
setMethod("content", "RD1", function(x) x@content)
setMethod("content", "RD1", function(object) object@content)
#' @export
setMethod("country", "RD1", function(x) x@country)
setMethod("country", "RD1", function(object) object@country)
#' @export
setMethod("protocol", "RD1", function(x) x@protocol)
setMethod("protocol", "RD1", function(object) object@protocol)

# slot setters
#' @export
setReplaceMethod("rd1", "RD1", function(x, value) {x@rd1 <- value; validObject(x); x})
setReplaceMethod("rd1", "RD1", function(object, value) {object@rd1 <- value; validObject(object); object})

# constructor
#' @export
Expand All @@ -55,18 +55,18 @@ setMethod("show", "RD1",
)

#' @export
setMethod("selectYears", "RD1", function(x, selectYears) {
setMethod("selectYears", "RD1", function(object, selectYears) {
Year <- NULL # evoid NOTE
.rd1 <- x@rd1[Year %in% selectYears]
return(new("RD1", header=x@header, footer=x@footer, rd1=.rd1, content=x@content, country=x@country, protocol=x@protocol))
.rd1 <- object@rd1[Year %in% selectYears]
return(new("RD1", header=object@header, footer=object@footer, rd1=.rd1, content=object@content, country=object@country, protocol=object@protocol))
}
)

#' @export
setMethod("selectRegion", "RD1", function(x, selectRegion) {
setMethod("selectRegion", "RD1", function(object, selectRegion) {
Region_Code <- NULL # evoid NOTE
.rd1 <- x@rd1[Region_Code %in% selectRegion]
return(new("RD1", header=x@header, footer=x@footer, rd1=.rd1, content=x@content, country=x@country, protocol=x@protocol))
.rd1 <- object@rd1[Region_Code %in% selectRegion]
return(new("RD1", header=object@header, footer=object@footer, rd1=.rd1, content=object@content, country=object@country, protocol=object@protocol))
}
)

Expand Down Expand Up @@ -105,22 +105,22 @@ setClass("RE1",

# slot getters
#' @export
setMethod("header", "RE1", function(x) x@header)
setMethod("header", "RE1", function(object) object@header)
#' @export
setMethod("footer", "RE1", function(x) x@footer)
setMethod("footer", "RE1", function(object) object@footer)
#' @export
setMethod("re1", "RE1", function(x) x@re1)
setMethod("re1", "RE1", function(object) object@re1)

#' @export
setMethod("content", "RE1", function(x) x@content)
setMethod("content", "RE1", function(object) object@content)
#' @export
setMethod("country", "RE1", function(x) x@country)
setMethod("country", "RE1", function(object) object@country)
#' @export
setMethod("protocol", "RE1", function(x) x@protocol)
setMethod("protocol", "RE1", function(object) object@protocol)

# slot setters
#' @export
setReplaceMethod("re1", "RE1", function(x, value) {x@re1 <- value; validObject(x); x})
setReplaceMethod("re1", "RE1", function(object, value) {object@re1 <- value; validObject(object); object})

# constructor
#' @export
Expand All @@ -138,18 +138,18 @@ setMethod("show", "RE1",
)

#' @export
setMethod("selectYears", "RE1", function(x, selectYears) {
setMethod("selectYears", "RE1", function(object, selectYears) {
Year <- NULL # evoid NOTE
.re1 <- x@re1[Year %in% selectYears]
return(new("RE1", header=x@header, footer=x@footer, re1=.re1, content=x@content, country=x@country, protocol=x@protocol))
.re1 <- object@re1[Year %in% selectYears]
return(new("RE1", header=object@header, footer=object@footer, re1=.re1, content=object@content, country=object@country, protocol=object@protocol))
}
)

#' @export
setMethod("selectRegion", "RE1", function(x, selectRegion) {
setMethod("selectRegion", "RE1", function(object, selectRegion) {
Region_Code <- NULL # evoid NOTE
.re1 <- x@re1[Region_Code %in% selectRegion]
return(new("RE1", header=x@header, footer=x@footer, re1=.re1, content=x@content, country=x@country, protocol=x@protocol))
.re1 <- object@re1[Region_Code %in% selectRegion]
return(new("RE1", header=object@header, footer=object@footer, re1=.re1, content=object@content, country=object@country, protocol=object@protocol))
}
)

Expand Down
119 changes: 86 additions & 33 deletions R/HMDClasses.R
Expand Up @@ -9,18 +9,21 @@ NULL
## S4 class definitions


#' LT1 class for life-tables 1x1
#' LT1 class for HMD life-tables 1x1
#'
#' The class \code{LT1} stores life-table information in a systematic way.
#' It fits to Human Mortality Database (HMD) 1x1 period life tables.
#' The class \code{LT1} stores HMD life table information in a systematic way.
#'
#' This \code{LT1} class fits to Human Mortality Database (HMD) 1x1 period life tables.
#' See https://www.mortality.org/ for data details.
#' An LT1 instance stores the raw header content and the life table as data.table.
#' Further it adds a pure numeric age AgeLow to the data.table.
#' An LT1 instance stores the raw header, the content,
#' the version protocol and regional information and the
#' life table as a data.table object.
#' The validation adds a pure numeric age AgeLow to the life table.
#'
#' @slot content describes the content
#' @slot country regional entity
#' @slot header includes the raw header information
#' @slot lt1 ist the life table (data.table)
#' @slot lt1 stores the life table (data.table)
#' @slot protocol contains the protocol information
#' @export
#' @rdname LT1-class
Expand All @@ -39,66 +42,116 @@ setClass("LT1",
#' LT1 header
#'
#' The \code{header}-method gets the raw header information of an LT1 object
#' @param x LT1-object
#' @return raw header information
#'
#' @param object LT1-object
#' @return The \code{header}-method returns the raw header information
#' @export
#' @rdname LT1-class
setMethod("header", "LT1", function(x) x@header)
#' @export
setMethod("lt1", "LT1", function(x) x@lt1)
setMethod("header", "LT1", function(object) object@header)

#' LT1 lt1
#'
#' The \code{lt1}-method gets the life table information of an LT1 object
#'
#' @return The \code{lt1}-method returns the life-table
#' @export
setMethod("content", "LT1", function(x) x@content)
#' @rdname LT1-class
setMethod("lt1", "LT1", function(object) object@lt1)

#' LT1 content
#'
#' The \code{content}-method gets the life table information of an LT1 object
#'
#' @return The \code{content}-method returns the content information
#' @export
setMethod("country", "LT1", function(x) x@country)
#' @rdname LT1-class
setMethod("content", "LT1", function(object) object@content)

#' LT1 country
#'
#' The \code{country}-method gets the regional information of an LT1 object
#'
#' @return The \code{country}-method returns the regional information
#' @export
setMethod("protocol", "LT1", function(x) x@protocol)
#' @rdname LT1-class
setMethod("country", "LT1", function(object) object@country)

# slot setters
#' LT1 protocol
#'
#' The \code{protocol}-method gets the protocol information of an LT1 object
#'
#' @return The \code{protocol}-method returns the protocol information
#' @export
setReplaceMethod("lt1", "LT1", function(x, value) {x@lt1 <- value; validObject(x); x})
#' @rdname LT1-class
setMethod("protocol", "LT1", function(object) object@protocol)

## slot setters

#' LT1 lt1<-
#'
#' The \code{lt1<-}-method allows to modify the life table information in a LT1 object
#'
#' @param value data.table
#' @return The \code{lt1<-}-method changes the life table information
#' @export
#' @rdname LT1-class
setReplaceMethod("lt1", "LT1", function(object, value) {object@lt1 <- value; validObject(object); object})


## constructor

#' LT1 constructor
#'
#' The \code{LTable1}-constructor creates an LT1 object
#' @param object header lt1 content country protocol
#' @return LT1 object
#'
#' @param header vector
#' @param lt1 data.table
#' @param content character
#' @param country character
#' @param protocol character
#' @return The \code{LTable1}-constructor returns an LT1 object
#' @export
#' @rdname LT1-class
LTable1 <- function(header, lt1, content, country, protocol)
new("LT1", header=header, lt1=lt1, content=content, country=country, protocol=protocol)

## methods


#' LT1 length
#'
#' The \code{length}-method gets the number of rows int the LT1 lt1 data.table
#' @param x LT1-object
#' @return number of rows
#' @return The \code{length}-method returns the number of rows
#' @export
#' @rdname LT1-class
setMethod("length", "LT1", function(x) dim(x@lt1)[1])

#' LT1 show
#'
#' @export
#' @rdname LT1-class
setMethod("show", "LT1",
function(object)
cat(class(object), "instance with length", length(object), "\n")
)

#' LT1 selectYears
#'
#' The \code{selectYears}-method gets a subset of an the LT1 object
#'
#' @param selectYears vector
#' @return The \code{selectYears}-method returns an LT1 object
#' @export
setMethod("selectYears", "LT1", function(x, selectYears) {
#' @rdname LT1-class
setMethod("selectYears", "LT1", function(object, selectYears) {
Year <- NULL # evoid NOTE
.lt1 <- x@lt1[Year %in% selectYears]
return(new("LT1", header=x@header, lt1=.lt1, content=x@content, country=x@country, protocol=x@protocol))
.lt1 <- object@lt1[Year %in% selectYears]
return(new("LT1", header=object@header, lt1=.lt1, content=object@content, country=object@country, protocol=object@protocol))
}
)

# validity method
## validity method

#' @export
setValidity("LT1",
function(object) {
Expand Down Expand Up @@ -140,20 +193,20 @@ setClass("EX1",

# slot getters
#' @export
setMethod("header", "EX1", function(x) x@header)
setMethod("header", "EX1", function(object) object@header)
#' @export
setMethod("ex1", "EX1", function(x) x@ex1)
setMethod("ex1", "EX1", function(object) object@ex1)

#' @export
setMethod("content", "EX1", function(x) x@content)
setMethod("content", "EX1", function(object) object@content)
#' @export
setMethod("country", "EX1", function(x) x@country)
setMethod("country", "EX1", function(object) object@country)
#' @export
setMethod("protocol", "EX1", function(x) x@protocol)
setMethod("protocol", "EX1", function(object) object@protocol)

# slot setters
#' @export
setReplaceMethod("ex1", "EX1", function(x, value) {x@ex1 <- value; validObject(x); x})
setReplaceMethod("ex1", "EX1", function(object, value) {object@ex1 <- value; validObject(object); object})

# constructor
#' @export
Expand All @@ -170,10 +223,10 @@ setMethod("show", "EX1",
)

#' @export
setMethod("selectYears", "EX1", function(x, selectYears) {
setMethod("selectYears", "EX1", function(object, selectYears) {
Year <- NULL # evoid NOTE
.ex1 <- x@ex1[Year %in% selectYears]
return(new("EX1", header=x@header, ex1=.ex1, content=x@content, country=x@country, protocol=x@protocol))
.ex1 <- object@ex1[Year %in% selectYears]
return(new("EX1", header=object@header, ex1=.ex1, content=object@content, country=object@country, protocol=object@protocol))
}
)

Expand Down

0 comments on commit ac4709d

Please sign in to comment.