diff --git a/R/AllGeneric.R b/R/AllGeneric.R index 5b4a4e6..8052771 100644 --- a/R/AllGeneric.R +++ b/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<-")) diff --git a/R/GENESISClasses.R b/R/GENESISClasses.R index 6295754..6c99c2f 100644 --- a/R/GENESISClasses.R +++ b/R/GENESISClasses.R @@ -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 @@ -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)) } ) @@ -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 @@ -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)) } ) diff --git a/R/HMDClasses.R b/R/HMDClasses.R index f6a373f..a5a2d35 100644 --- a/R/HMDClasses.R +++ b/R/HMDClasses.R @@ -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 @@ -39,25 +42,60 @@ 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 @@ -65,8 +103,13 @@ setReplaceMethod("lt1", "LT1", function(x, value) {x@lt1 <- value; validObject(x #' 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) @@ -74,31 +117,41 @@ LTable1 <- function(header, lt1, content, country, 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) { @@ -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 @@ -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)) } ) diff --git a/man/LT1-class.Rd b/man/LT1-class.Rd index cd834af..4b25c4e 100644 --- a/man/LT1-class.Rd +++ b/man/LT1-class.Rd @@ -4,42 +4,103 @@ \name{LT1-class} \alias{LT1-class} \alias{header,LT1-method} +\alias{lt1,LT1-method} +\alias{content,LT1-method} +\alias{country,LT1-method} +\alias{protocol,LT1-method} +\alias{lt1<-,LT1-method} \alias{LTable1} \alias{length,LT1-method} -\title{LT1 class for life-tables 1x1} +\alias{show,LT1-method} +\alias{selectYears,LT1-method} +\title{LT1 class for HMD life-tables 1x1} \usage{ -\S4method{header}{LT1}(x) +\S4method{header}{LT1}(object) + +\S4method{lt1}{LT1}(object) + +\S4method{content}{LT1}(object) + +\S4method{country}{LT1}(object) + +\S4method{protocol}{LT1}(object) + +\S4method{lt1}{LT1}(object) <- value LTable1(header, lt1, content, country, protocol) \S4method{length}{LT1}(x) + +\S4method{show}{LT1}(object) + +\S4method{selectYears}{LT1}(object, selectYears) } \arguments{ -\item{x}{LT1-object} +\item{object}{LT1-object} -\item{object}{header lt1 content country protocol} +\item{value}{data.table} + +\item{header}{vector} + +\item{lt1}{data.table} + +\item{content}{character} + +\item{country}{character} + +\item{protocol}{character} \item{x}{LT1-object} + +\item{selectYears}{vector} } \value{ -raw header information +The \code{header}-method returns the raw header information + +The \code{lt1}-method returns the life-table -LT1 object +The \code{content}-method returns the content information -number of rows +The \code{country}-method returns the regional information + +The \code{protocol}-method returns the protocol information + +The \code{lt1<-}-method changes the life table information + +The \code{LTable1}-constructor returns an LT1 object + +The \code{length}-method returns the number of rows + +The \code{selectYears}-method returns an LT1 object } \description{ -The class \code{LT1} stores life-table information in a systematic way. -It 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. +The class \code{LT1} stores HMD life table information in a systematic way. The \code{header}-method gets the raw header information of an LT1 object +The \code{lt1}-method gets the life table information of an LT1 object + +The \code{content}-method gets the life table information of an LT1 object + +The \code{country}-method gets the regional information of an LT1 object + +The \code{protocol}-method gets the protocol information of an LT1 object + +The \code{lt1<-}-method allows to modify the life table information in a LT1 object + The \code{LTable1}-constructor creates an LT1 object The \code{length}-method gets the number of rows int the LT1 lt1 data.table + +The \code{selectYears}-method gets a subset of an the LT1 object +} +\details{ +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, 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. } \section{Slots}{ @@ -50,7 +111,7 @@ The \code{length}-method gets the number of rows int the LT1 lt1 data.table \item{\code{header}}{includes the raw header information} -\item{\code{lt1}}{ist the life table (data.table)} +\item{\code{lt1}}{stores the life table (data.table)} \item{\code{protocol}}{contains the protocol information} }}