Skip to content
Snippets Groups Projects
Commit 7d2f12e9 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Generalize mortalityTables.list and mortalityTables.load

- mortalityTables.list and mortalityTables.load can be given multiple packages (defaults to "MortalityTables" and "MortalityTablesPrivate")
- mortalityTables.load supports wildcards in its default call (no need for the wildcard=TRUE argument)

Move anwartschaften.R to the pensionstafel project (forgot to update build system)
parent 84df6e4e
Branches
Tags
No related merge requests found
......@@ -32,8 +32,6 @@ Collate:
'mortalityTable.joined.R'
'mortalityTable.mixed.R'
'ages.R'
'pensionTable.R'
'anwartschaften.R'
'baseTable.R'
'baseYear.R'
'mortalityTable.improvementFactors.R'
......@@ -49,6 +47,7 @@ Collate:
'mortalityTable.jointLives.R'
'mortalityTables.list.R'
'mortalityTables.load.R'
'pensionTable.R'
'plot.mortalityTable.R'
'plotMortalityTableComparisons.R'
'plotMortalityTables.R'
......
......@@ -4,13 +4,18 @@
#' @param pattern Restrict the results only to life table sets that match the pattern (default: "*" to show all sets)
#' @param package The package that contains the desired dataset in its \code{extdata/}
#' directory. Defaults to the "MortalityTables" package.
#' Multiple packages can be given as a vector.
#' @param prefix The file prefix, defaults to MortalityTables. Can be overridden to list other types of files, like "PensionTables"
#'
#' @export
mortalityTables.list = function(pattern = "*", package = "MortalityTables", prefix = "MortalityTables") {
filepath = system.file("extdata", package = package);
files = Sys.glob(file.path(filepath, paste(prefix, "_", pattern, ".R", sep = "")))
gsub(paste('^', prefix, '_(.*).R$', sep = ""), '\\1', basename(files))
mortalityTables.list = function(pattern = "*", package = c("MortalityTables", "MortalityTablesPrivate"), prefix = "MortalityTables") {
ret = c()
for (p in c(package)) {
filepath = system.file("extdata", package = p);
files = Sys.glob(file.path(filepath, paste(prefix, "_", pattern, ".R", sep = "")))
ret = c(ret, gsub(paste('^', prefix, '_(.*).R$', sep = ""), '\\1', basename(files)))
}
ret
}
......@@ -20,8 +25,9 @@ mortalityTables.list = function(pattern = "*", package = "MortalityTables", pref
#' @param pattern Restrict the results only to pension table sets that match the pattern (default: "*" to show all sets)
#' @param package The package that contains the desired dataset in its \code{extdata/}
#' directory. Defaults to the "MortalityTables" package.
#' Multiple packages can be given as a vector.
#'
#' @export
pensionTables.list = function(pattern = "*", package = "MortalityTables") {
pensionTables.list = function(pattern = "*", package = c("MortalityTables", "MortalityTablesPrivate")) {
mortalityTables.list(pattern = pattern, package = package, prefix = "PensionTables")
}
#' Load a named set of mortality tables provided by the \link{MortalityTables} package
#'
#' @param dataset The set of life tables to be loaded. A list of all available
#' @param dataset The set(s) of life tables to be loaded. A list of all available
#' data sets is provided by the function \code{\link{mortalityTables.list}}.
#' @param wildcard Whether the dataset name contains wildcard. If TRUE, all
#' datasets matching the pattern will be loaded
#' Wildcards (*) are allowed to match and load multiple datasets.
#' @param package The package that contains the dataset in its \code{extdata/}
#' directory. Defaults to the "MortalityTables" package.
#' @param prefix The prefix for the data sets (default is "MortalityTables")
#' Multiple packages can be given as a vector.
#' @param prefix The prefix for the data sets (default is "MortalityTables").
#'
#' @export
mortalityTables.load = function(dataset, wildcard = FALSE, package = "MortalityTables", prefix = "MortalityTables") {
if (wildcard) {
sets = mortalityTables.list(dataset, package = package, prefix = prefix);
} else {
sets = c(dataset);
mortalityTables.load = function(dataset, package = c("MortalityTables", "MortalityTablesPrivate"), prefix = "MortalityTables") {
sets = mortalityTables.list(dataset, package = package, prefix = prefix);
if (length(sets) == 0) {
warning(sprintf("Unable to locate dataset '%s' provided by the %s package!", dataset, paste(c(package), collapse = " or ")));
}
for (set in sets) {
sname = gsub("[^-A-Za-z0-9_.]", "", set);
message("Loading table dataset '", sname, "'");
filename = system.file("extdata", paste(prefix, "_", sname, ".R", sep = ""), package = package);
if (filename != "") {
sys.source(filename, envir = globalenv())
} else {
loaded = FALSE;
for (p in c(package)) {
filename = system.file("extdata", paste(prefix, "_", sname, ".R", sep = ""), package = p);
if (filename != "") {
sys.source(filename, envir = globalenv())
loaded = TRUE
}
}
if (!loaded) {
warning(sprintf("Unable to locate dataset '%s' provided by the %s package!", sname, package));
}
}
......@@ -32,14 +36,14 @@ mortalityTables.load = function(dataset, wildcard = FALSE, package = "MortalityT
#'
#' @param dataset The set of lifpensione tables to be loaded. A list of all available
#' data sets is provided by the function \code{\link{pensionTables.list}}.
#' @param wildcard Whether the dataset name contains wildcard. If TRUE, all
#' datasets matching the pattern will be loaded
#' Wildcards (*) are allowed to match and load multiple datasets.
#' @param package The package that contains the dataset in its \code{extdata/}
#' directory. Defaults to the "MortalityTables" package.
#' Multiple packages can be given as a vector.
#'
#' @export
pensionTables.load = function(dataset, wildcard = FALSE, package = "MortalityTables") {
mortalityTables.load(dataset = dataset, wildcard = wildcard, package = package, prefix = "PensionTables")
pensionTables.load = function(dataset, package = c("MortalityTables", "MortalityTablesPrivate")) {
mortalityTables.load(dataset = dataset, package = package, prefix = "PensionTables")
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/anwartschaften.R
\docType{methods}
\name{anwartschaften}
\alias{anwartschaften}
\alias{anwartschaften,pensionTable-method}
\title{Calculates all "anwartschaften" for the gien pension table}
\usage{
anwartschaften(object, ...)
\S4method{anwartschaften}{pensionTable}(object, ..., i = 0.03, YOB = 1982,
Period = NULL)
}
\arguments{
\item{object}{A pension table object (instance of a \code{\linkS4class{pensionTable}} class)}
\item{...}{Currently unused}
\item{i}{Interest rate (default 0.03)}
\item{YOB}{Year of birth (default 1982)}
}
\description{
Calculates all "anwartschaften" for the gien pension table
}
\section{Methods (by class)}{
\itemize{
\item \code{pensionTable}: Calculates all "anwartschaften" for the gien pension table
}}
\examples{
pensionTables.load("Austria_*", wildcard=TRUE)
# anwartschaften(EttlPagler.male, i=0.03, YOB=1972)
}
......@@ -5,14 +5,15 @@
\title{List all available sets of life tables provided by the \link[MortalityTables]{MortalityTables-package} package
An existing life table can then be loaded with \link{mortalityTables.load}.}
\usage{
mortalityTables.list(pattern = "*", package = "MortalityTables",
prefix = "MortalityTables")
mortalityTables.list(pattern = "*", package = c("MortalityTables",
"MortalityTablesPrivate"), prefix = "MortalityTables")
}
\arguments{
\item{pattern}{Restrict the results only to life table sets that match the pattern (default: "*" to show all sets)}
\item{package}{The package that contains the desired dataset in its \code{extdata/}
directory. Defaults to the "MortalityTables" package.}
directory. Defaults to the "MortalityTables" package.
Multiple packages can be given as a vector.}
\item{prefix}{The file prefix, defaults to MortalityTables. Can be overridden to list other types of files, like "PensionTables"}
}
......
......@@ -4,20 +4,19 @@
\alias{mortalityTables.load}
\title{Load a named set of mortality tables provided by the \link{MortalityTables} package}
\usage{
mortalityTables.load(dataset, wildcard = FALSE, package = "MortalityTables",
prefix = "MortalityTables")
mortalityTables.load(dataset, package = c("MortalityTables",
"MortalityTablesPrivate"), prefix = "MortalityTables")
}
\arguments{
\item{dataset}{The set of life tables to be loaded. A list of all available
data sets is provided by the function \code{\link{mortalityTables.list}}.}
\item{wildcard}{Whether the dataset name contains wildcard. If TRUE, all
datasets matching the pattern will be loaded}
\item{dataset}{The set(s) of life tables to be loaded. A list of all available
data sets is provided by the function \code{\link{mortalityTables.list}}.
Wildcards (*) are allowed to match and load multiple datasets.}
\item{package}{The package that contains the dataset in its \code{extdata/}
directory. Defaults to the "MortalityTables" package.}
directory. Defaults to the "MortalityTables" package.
Multiple packages can be given as a vector.}
\item{prefix}{The prefix for the data sets (default is "MortalityTables")}
\item{prefix}{The prefix for the data sets (default is "MortalityTables").}
}
\description{
Load a named set of mortality tables provided by the \link{MortalityTables} package
......
......@@ -5,13 +5,15 @@
\title{List all available sets of pension tables provided by the \link[MortalityTables]{MortalityTables-package} package
An existing pension table can then be loaded with \link{pensionTables.load}.}
\usage{
pensionTables.list(pattern = "*", package = "MortalityTables")
pensionTables.list(pattern = "*", package = c("MortalityTables",
"MortalityTablesPrivate"))
}
\arguments{
\item{pattern}{Restrict the results only to pension table sets that match the pattern (default: "*" to show all sets)}
\item{package}{The package that contains the desired dataset in its \code{extdata/}
directory. Defaults to the "MortalityTables" package.}
directory. Defaults to the "MortalityTables" package.
Multiple packages can be given as a vector.}
}
\description{
List all available sets of pension tables provided by the \link[MortalityTables]{MortalityTables-package} package
......
......@@ -4,17 +4,17 @@
\alias{pensionTables.load}
\title{Load a named set of pension tables provided by the \link{MortalityTables} package}
\usage{
pensionTables.load(dataset, wildcard = FALSE, package = "MortalityTables")
pensionTables.load(dataset, package = c("MortalityTables",
"MortalityTablesPrivate"))
}
\arguments{
\item{dataset}{The set of lifpensione tables to be loaded. A list of all available
data sets is provided by the function \code{\link{pensionTables.list}}.}
\item{wildcard}{Whether the dataset name contains wildcard. If TRUE, all
datasets matching the pattern will be loaded}
data sets is provided by the function \code{\link{pensionTables.list}}.
Wildcards (*) are allowed to match and load multiple datasets.}
\item{package}{The package that contains the dataset in its \code{extdata/}
directory. Defaults to the "MortalityTables" package.}
directory. Defaults to the "MortalityTables" package.
Multiple packages can be given as a vector.}
}
\description{
Load a named set of pension tables provided by the \link{MortalityTables} package
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment