diff --git a/R/contractGrid.R b/R/contractGrid.R index f7be7c45516f70db6066136a2db47b97fd9dfea0..e1042f17b62d49313b6761d09dde00b34474bce0 100644 --- a/R/contractGrid.R +++ b/R/contractGrid.R @@ -27,7 +27,9 @@ #' contract object. #' #' To create the human-readable row-/columnnames of the resulting array, -#' the function [make.] +#' the function [makeContractGridDimname()] for each value of the axes, allowing +#' human-readable representations e.g. of a tariff or a mortality table as +#' the dimension label. #' #' #' @@ -70,39 +72,53 @@ contractGrid = function(axes = list(age = seq(20, 60, 10), policyPeriod = seq(5, array(vals, dim = sapply(axes, length), dimnames = dimnames) } -#' @describeIn makeContractGridDimname Create a dimensional name for an [InsuranceTarif] object +# describeIn makeContractGridDimname Create a dimensional name for an [InsuranceTarif] object #' @export makeContractGridDimname.InsuranceTarif = function(value) { value$name } -#' @describeIn makeContractGridDimname Create a dimensional name for an R6 object (using its \code{name} field) +# describeIn makeContractGridDimname Create a dimensional name for an R6 object (using its \code{name} field) #' @export makeContractGridDimname.R6 = function(value) { value$name } -#' @describeIn makeContractGridDimname Create a dimensional name for an [mortalityTable] object +# describeIn makeContractGridDimname Create a dimensional name for an [mortalityTable] object #' @export makeContractGridDimname.mortalityTable = function(value) { value@name } -#' @describeIn makeContractGridDimname Create a dimensional name for a numeric parameter value +# describeIn makeContractGridDimname Create a dimensional name for a numeric parameter value #' @export makeContractGridDimname.numeric = function(value) { value } -#' @describeIn makeContractGridDimname Create a dimensional name for a numeric parameter value +# describeIn makeContractGridDimname Create a dimensional name for a numeric parameter value #' @export makeContractGridDimname.double = function(value) { value } -#' @describeIn makeContractGridDimname Create a dimensional name for an object that can be directly used as a human-readable row-/columnname +# describeIn makeContractGridDimname Create a dimensional name for an object that can be directly used as a human-readable row-/columnname #' @export makeContractGridDimname.default = function(value) { value } #' Create human-readable labels for the dimensions in a [contractGrid()] #' -#' The funciton \code{makeContractGridDimname} generates a short, human-readable -#' dimension label for the object passed as \code{value}, to be used in [contractGrid]. +#' The function \code{makeContractGridDimname} generates a short, human-readable +#' dimension label for the entries along the axes of a [contractGrid()]. #' The default is to use the \code{value} unchanged as the row-/columnname, but #' for some parameter values (like a [InsuranceTarif] or [mortalityTable]) #' a custom method of this function is needed to create the (short) human-readable #' representation for the axes in the grid. +#' #' @param value the value along the axis, for which a name should be generated -# describeIn makeContractGridDimname Create a short, human-readable dimensional name for an object (default S3 method) +#' @describeIn makeContractGridDimname Create a short, human-readable dimensional name for an object (default S3 method) +#' @examples +#' library(MortalityTables) +#' mortalityTables.load("Austria_Census") +#' +#' makeContractGridDimname(mort.AT.census.2011.unisex) +#' +#' makeContractGridDimnames(axes = list( +#' age = seq(30,60,10), +#' mortalityTable = c(mort.AT.census.2011.unisex, mort.AT.census.2011.male, mort.AT.census.2011.female)) +#' ) #' @export makeContractGridDimname = function(value) { UseMethod("makeContractGridDimname", value) } -#' Generate proper dimnames for all entries of the axes of a [contractGrid()] + +#' @description The function \code{makeContractGridDimnames} generate proper +#' dimnames for all entries of the axes of a [contractGrid()] by calling +#' \code{makeContractGridDimname} on each of the axes' values #' @param axes the axes with all names, for which a name should be generated -#' @describeIn makeContractGridDimnames Generate proper dimnames for all entries of the axes of a [contractGrid()] +#' @describeIn makeContractGridDimname Generate proper dimnames for all entries of the axes of a [contractGrid()] #' @export makeContractGridDimnames = function(axes) { lapply(axes, function(axis) { lapply(axis, makeContractGridDimname); } ) @@ -134,11 +150,11 @@ makeContractGridDimnames = function(axes) { #' #' @rdname contractGrid #' @export -contractGridPremium = function(contractGrid = NULL, premium="written", .fun = function(c) { c[[1]]$Values$premiums[[premium]] }, ...) { +contractGridPremium = function(contractGrid = NULL, premium="written", .fun = function(cntr) { cntr$Values$premiums[[premium]] }, ...) { if (missing(contractGrid) || is.null(contractGrid)) { contractGrid = contractGrid(...) } - apply(contractGrid, 1:length(dim(contractGrid)), .fun) + apply(contractGrid, 1:length(dim(contractGrid)), function(c) { .fun(c[[1]])}) } diff --git a/man/contractGrid.Rd b/man/contractGrid.Rd index ed0ef986125bded941d9d021dc1713460e255502..f851541b2abd5ad535c8f5f95dfacf4a3501b0a7 100644 --- a/man/contractGrid.Rd +++ b/man/contractGrid.Rd @@ -15,7 +15,7 @@ contractGrid( contractGridPremium( contractGrid = NULL, premium = "written", - .fun = function(c) { c[[1]]$Values$premiums[[premium]] }, + .fun = function(cntr) { cntr$Values$premiums[[premium]] }, ... ) } @@ -68,7 +68,9 @@ is then passed to the \code{\link[=InsuranceContract$new]{InsuranceContract$new( contract object. To create the human-readable row-/columnnames of the resulting array, -the function \link{make.} +the function \code{\link[=makeContractGridDimname]{makeContractGridDimname()}} for each value of the axes, allowing +human-readable representations e.g. of a tariff or a mortality table as +the dimension label. } \examples{ # TODO diff --git a/man/makeContractGridDimname.Rd b/man/makeContractGridDimname.Rd index 97cac4a8fcb8439198c60331ce3348e2d1928837..da97d4d170b16ee25e6958e1fc0b3a36bb641bb4 100644 --- a/man/makeContractGridDimname.Rd +++ b/man/makeContractGridDimname.Rd @@ -1,52 +1,46 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/contractGrid.R -\name{makeContractGridDimname.InsuranceTarif} -\alias{makeContractGridDimname.InsuranceTarif} -\alias{makeContractGridDimname.R6} -\alias{makeContractGridDimname.mortalityTable} -\alias{makeContractGridDimname.numeric} -\alias{makeContractGridDimname.double} -\alias{makeContractGridDimname.default} +\name{makeContractGridDimname} \alias{makeContractGridDimname} +\alias{makeContractGridDimnames} \title{Create human-readable labels for the dimensions in a \code{\link[=contractGrid]{contractGrid()}}} \usage{ -\method{makeContractGridDimname}{InsuranceTarif}(value) - -\method{makeContractGridDimname}{R6}(value) - -\method{makeContractGridDimname}{mortalityTable}(value) - -\method{makeContractGridDimname}{numeric}(value) - -\method{makeContractGridDimname}{double}(value) - -\method{makeContractGridDimname}{default}(value) - makeContractGridDimname(value) + +makeContractGridDimnames(axes) } \arguments{ \item{value}{the value along the axis, for which a name should be generated} + +\item{axes}{the axes with all names, for which a name should be generated} } \description{ -The funciton \code{makeContractGridDimname} generates a short, human-readable -dimension label for the object passed as \code{value}, to be used in \link{contractGrid}. +The function \code{makeContractGridDimname} generates a short, human-readable +dimension label for the entries along the axes of a \code{\link[=contractGrid]{contractGrid()}}. The default is to use the \code{value} unchanged as the row-/columnname, but -for some parameter values (like a \link{InsuranceTarif} or \link{MortalityTable}) +for some parameter values (like a \link{InsuranceTarif} or \link{mortalityTable}) a custom method of this function is needed to create the (short) human-readable representation for the axes in the grid. + +The function \code{makeContractGridDimnames} generate proper +dimnames for all entries of the axes of a \code{\link[=contractGrid]{contractGrid()}} by calling +\code{makeContractGridDimname} on each of the axes' values } -\section{Methods (by class)}{ +\section{Functions}{ \itemize{ -\item \code{InsuranceTarif}: Create a dimensional name for an \link{InsuranceTarif} object - -\item \code{R6}: Create a dimensional name for an R6 object (using its \code{name} field) - -\item \code{mortalityTable}: Create a dimensional name for an \link{MortalityTable} object +\item \code{makeContractGridDimname}: Create a short, human-readable dimensional name for an object (default S3 method) -\item \code{numeric}: Create a dimensional name for a numeric parameter value +\item \code{makeContractGridDimnames}: Generate proper dimnames for all entries of the axes of a \code{\link[=contractGrid]{contractGrid()}} +}} -\item \code{double}: Create a dimensional name for a numeric parameter value +\examples{ +library(MortalityTables) +mortalityTables.load("Austria_Census") -\item \code{default}: Create a dimensional name for an object that can be directly used as a human-readable row-/columnname -}} +makeContractGridDimname(mort.AT.census.2011.unisex) +makeContractGridDimnames(axes = list( + age = seq(30,60,10), + mortalityTable = c(mort.AT.census.2011.unisex, mort.AT.census.2011.male, mort.AT.census.2011.female)) +) +} diff --git a/man/makeContractGridDimnames.Rd b/man/makeContractGridDimnames.Rd deleted file mode 100644 index 989aacf1593f935385dc20b5d032dad264795169..0000000000000000000000000000000000000000 --- a/man/makeContractGridDimnames.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/contractGrid.R -\name{makeContractGridDimnames} -\alias{makeContractGridDimnames} -\title{Generate proper dimnames for all entries of the axes of a \code{\link[=contractGrid]{contractGrid()}}} -\usage{ -makeContractGridDimnames(axes) -} -\arguments{ -\item{axes}{the axes with all names, for which a name should be generated} -} -\description{ -Generate proper dimnames for all entries of the axes of a \code{\link[=contractGrid]{contractGrid()}} -} -\section{Functions}{ -\itemize{ -\item \code{makeContractGridDimnames}: Generate proper dimnames for all entries of the axes of a \code{\link[=contractGrid]{contractGrid()}} -}} -