From 595957f28a518b8982e597ed1c9f6249270325d8 Mon Sep 17 00:00:00 2001
From: Reinhold Kainhofer <reinhold@kainhofer.com>
Date: Wed, 7 Sep 2016 23:17:19 +0200
Subject: [PATCH] Add documentation, move dependency handling to roxygen

---
 .gitignore                       |  1 +
 DESCRIPTION                      |  7 ++++++-
 NAMESPACE                        | 10 ++++++++++
 R/InsuranceContract.R            | 27 ++++++++++++++++++++-------
 R/InsuranceParameters.R          | 30 ++++++++++++++++++++++--------
 R/InsuranceTarif.R               | 19 ++++++++++---------
 R/ProfitParticipation.R          | 12 ++++++++----
 R/exportInsuranceContract_xlsx.R | 12 ++++++++++--
 8 files changed, 87 insertions(+), 31 deletions(-)

diff --git a/.gitignore b/.gitignore
index 58e9fba..20f245e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@ R/Companies/
 Formulas_Reference/2013*.xls*
 LifeInsuranceContracts.Rproj
 Vergleichsrechnung_Excel
+inst/doc
diff --git a/DESCRIPTION b/DESCRIPTION
index fb386f2..c10c22a 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -18,7 +18,12 @@ RoxygenNote: 5.0.1
 Collate:
     'HelperFunctions.R'
     'InsuranceParameters.R'
+    'ProfitParticipation.R'
     'InsuranceTarif.R'
     'InsuranceContract.R'
-    'ProfitParticipation.R'
+    'LifeInsuranceContracts.R'
     'exportInsuranceContract_xlsx.R'
+Suggests:
+    knitr,
+    rmarkdown
+VignetteBuilder: knitr
diff --git a/NAMESPACE b/NAMESPACE
index cd4cc84..e2217bb 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -1,5 +1,15 @@
 # Generated by roxygen2: do not edit by hand
 
+export(InsuranceContract)
+export(InsuranceContract.ParameterDefaults)
+export(InsuranceContract.ParametersFallback)
+export(InsuranceContract.ParametersFill)
+export(InsuranceContract.Values)
+export(InsuranceTarif)
+export(ProfitParticipation)
+export(exportInsuranceContract.xlsx)
+export(initializeCosts)
 import(R6)
 import(ValuationTables)
 import(lubridate)
+import(openxlsx)
diff --git a/R/InsuranceContract.R b/R/InsuranceContract.R
index 1ba6b5b..71d5ad5 100644
--- a/R/InsuranceContract.R
+++ b/R/InsuranceContract.R
@@ -1,10 +1,23 @@
-library(R6)
-library(openxlsx);
-library(ValuationTables);
-
-#' @include HelperFunctions.R
-#' @include InsuranceTarif.R
-
+#' @include HelperFunctions.R InsuranceParameters.R InsuranceTarif.R ProfitParticipation.R
+#'
+#' @import ValuationTables
+#' @import R6
+#' @import lubridate
+NULL
+
+
+
+#' Base Class for Insurance Contracts
+#'
+#' R6 class that models a complete, general insurance contract.
+#' The corresponding tariff and the profit participation scheme, as well as
+#' all other relevant contract parameters (if not defined by the tariff or
+#' explicitly overridden by the contract) can be given in the constructor.
+#'
+#' Immediately upon construction, all premiums, reserves and cash flows for the
+#' whole contract period are calculated.
+#'
+#' @export
 InsuranceContract = R6Class(
     "InsuranceContract",
 
diff --git a/R/InsuranceParameters.R b/R/InsuranceParameters.R
index ea33c39..b0b23e6 100644
--- a/R/InsuranceParameters.R
+++ b/R/InsuranceParameters.R
@@ -1,12 +1,13 @@
-# @include
+#' @import lubridate
+NULL
 
 
-
-# Initialize a cost matrix with dimensions: [CostType, Basis, Period], with:
-#     CostType: alpha, Zillmer, beta, gamma, gamma_nopremiums
-#     Basis:    SumInsured, SumPremiums, GrossPremium
-#     Period:   once, PremiumPeriod, PremiumFree, PolicyPeriod
-# TODO: gamma an Erlebensleistungen?
+#' Initialize a cost matrix with dimensions: [CostType, Basis, Period], with:
+#'     CostType: alpha, Zillmer, beta, gamma, gamma_nopremiums
+#'     Basis:    SumInsured, SumPremiums, GrossPremium
+#'     Period:   once, PremiumPeriod, PremiumFree, PolicyPeriod
+#' TODO: gamma an Erlebensleistungen?
+#' @export
 initializeCosts = function() {
   dimnm=list(
     c("alpha", "Zillmer", "beta", "gamma", "gamma_nopremiums"),
@@ -20,6 +21,7 @@ initializeCosts = function() {
 }
 
 
+#' @export
 InsuranceContract.Values = list(
   basicData = NULL,
   transitionProbabilities = NULL,
@@ -45,7 +47,8 @@ InsuranceContract.Values = list(
 
 
 
-InsuranceContract.ParameterStructure = list(
+#' @export
+InsuranceContract.ParameterDefaults = list(
   ContractData = list (
     sumInsured = NULL,
     YOB = NULL,
@@ -138,6 +141,17 @@ InsuranceContract.ParametersFill = function(params=InsuranceContract.ParameterSt
     params
 }
 
+#' InsuranceContract.ParametersFallback
+#'
+#' Provide default values for the insurance contract parameters if any of the
+#' parameters is not explicitly set.
+#'
+#' @param params Current, explicitly set contract parameters. All NULL values
+#'               will be filled with the corresponding entry from \code{fallback}.
+#' @param fallback Fallback values that will be used when the corresponding
+#'                 entry in \code{params} is NULL.
+#'
+#' @export
 InsuranceContract.ParametersFallback = function(params, fallback) {
     # params = InsuranceContract.ParameterStructure;
     params$ContractData = fallbackFields(params$ContractData, fallback$ContractData);
diff --git a/R/InsuranceTarif.R b/R/InsuranceTarif.R
index 4a2af5b..dbd0b54 100644
--- a/R/InsuranceTarif.R
+++ b/R/InsuranceTarif.R
@@ -5,19 +5,20 @@
 #' @import lubridate
 NULL
 
-# library(R6)
-# library(lifecontingencies)
-# library(objectProperties)
-# library(lubridate)
-
 
 TariffTypeEnum = setSingleEnum("TariffType", levels = c("annuity", "wholelife", "endowment", "pureendowment", "terme-fix", "dread-disease"))
 
 
-# base class for Insurance Tarifs (holding contrat-independent values and
-# providing methods to calculate cash flows, premiums, etc.). Objects of this
-# class do NOT contain contract-specific values like age, death probabilities,
-# premiums, reserves, etc.
+#' Base class for Insurance Tarifs, providing calculation functions to the contract
+#'
+#' This is a base class for holding contract-independent values and
+#' providing methods to calculate cash flows, premiums, etc. Objects of this
+#' class do NOT contain contract-specific values like age, death probabilities,
+#' premiums, reserves, etc. Rather, they are the calculation kernels that will
+#' be called by the \code{\link{InsuranceContract}} objects to make the actual,
+#' tariff-specific calculations.
+#'
+#' @export
 InsuranceTarif = R6Class(
   "InsuranceTarif",
   public  = list(
diff --git a/R/ProfitParticipation.R b/R/ProfitParticipation.R
index c1eaa26..1a42ae3 100644
--- a/R/ProfitParticipation.R
+++ b/R/ProfitParticipation.R
@@ -3,11 +3,15 @@
 #' @import R6
 NULL
 
-# library(R6)
 
-# base class for Profit Participation schemes  (holding contract-independent values and
-# providing methods to calculate the profit participation values from the given
-# reserves).
+
+#' Base Class for Profit Participation Schemes
+#'
+#' base class for Profit Participation schemes  (holding contract-independent values and
+#' providing methods to calculate the profit participation values from the given
+#' reserves).
+#'
+#' @export
 ProfitParticipation = R6Class(
   "ProfitParticipation",
   public  = list(
diff --git a/R/exportInsuranceContract_xlsx.R b/R/exportInsuranceContract_xlsx.R
index ebaf961..4855fad 100644
--- a/R/exportInsuranceContract_xlsx.R
+++ b/R/exportInsuranceContract_xlsx.R
@@ -1,5 +1,12 @@
-#' @include HelperFunctions.R
-library(openxlsx)
+#' @include HelperFunctions.R InsuranceContract.R InsuranceParameters.R InsuranceTarif.R ProfitParticipation.R
+#'
+#' @import openxlsx
+#' @import ValuationTables
+#' @import R6
+#' @import lubridate
+NULL
+
+
 
 ################################################
 # Helper Functions
@@ -180,6 +187,7 @@ setInsuranceValuesLabels = function(vals) {
 ################################################################################
 
 
+#' @export
 exportInsuranceContract.xlsx = function(contract, filename) {
   # TODO: argument checking for contract and filename
 
-- 
GitLab