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

Improve RStudio project template

* implement copying template files (placeholer replacements do not yet work)
* Start vignette
parent 379e4956
No related branches found
No related tags found
No related merge requests found
......@@ -5,45 +5,71 @@
# and heavily modified
create_LIC_project <- function(path, ...) {
# ensure path exists
dots <- list(...)
CompanyName = dots$Company
########################################
##### 1. ensure destination path exists, sanity checks on the company name
dir.create(path, recursive = TRUE, showWarnings = FALSE)
########################################
##### 2. copy over all files from the template directory
# LIC.src <- function (..., lib.loc = NULL, mustWork = FALSE){
# system.file(..., package = "LifeInsuranceContracts", lib.loc = lib.loc, mustWork = mustWork)
# }
#
# from <- LIC.src("templatedemo")
#
# fs::dir_copy(
# path = from,
# new_path = path,
# overwrite = TRUE
# )
# generate header for file
header <- c(
"# This file was generated by a call to 'ptexamples::hello_world()'.",
"# The following inputs were received:",
""
)
LIC.src <- function (..., lib.loc = NULL, mustWork = FALSE){
system.file("rstudio", "templates", "project", ...,
package = "LifeInsuranceContracts",
lib.loc = lib.loc, mustWork = mustWork)
}
from <- LIC.src("LifeInsuranceContracts")
copied_files <- fs::dir_copy(path = from, new_path = path, overwrite = TRUE)
# collect inputs and paste together as 'Parameter: Value'
dots <- list(...)
text <- lapply(seq_along(dots), function(i) {
key <- names(dots)[[i]]
val <- dots[[i]]
paste0(key, ": ", val)
})
# collect into single text string
contents <- paste(
paste(header, collapse = "\n"),
paste(text, collapse = "\n"),
sep = "\n"
########################################
##### 3. Rename all files with XXXCOMPANYXXX -> CompanyName
LIC.replaceFilename <- function(...) {
}
########################################
##### 4. Replace all file contents with XXXCOMPANYXXX -> CompanyName
LIC.replaceFileContents <- function(file, pattern, replace) {
suppressWarnings(tx <- readLines(file))
tx2 <- gsub(pattern = pattern, replacement = replace, x = tx)
writeLines(tx2, con = file)
}
LIC.replaceAllFilesContents <- function(
copied_files, pattern, replace, path) {
# Going through copied files to replace package name
for (f in copied_files) {
copied_file <- file.path(path, f)
try({
LIC.replaceFileContents(
file = copied_file,
pattern = pattern,
replace = replace
)
}, silent = TRUE)
}
}
LIC.replaceAllFilesContents(
copied_files,
pattern = "XXXCOMPANYXXX",
replace = CompanyName,
path
)
# write to index file
writeLines(contents, con = file.path(path, "RechnungGesamtbestand.R"))
########################################
##### 5. All other small tasks
}
---
title: "Creating Company-Specific LifeInsuranceContracts Implementations (using an RStudio Package Template)"
author:
- name: Reinhold Kainhofer
affiliation: Open Tools
email: reinhold@kainhofer.com
date: "`r Sys.Date()`"
output:
rmarkdown::html_vignette:
toc: true
toc_depth: 3
fig_width: 7
fig_height: 5
number_sections: true
vignette: >
%\VignetteIndexEntry{Using the LifeInsuranceContracts Package}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, echo = FALSE, message=FALSE}
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
library(knitr)
library(kableExtra)
library(LifeInsuranceContracts)
library(dplyr)
library(tibble)
library(lubridate)
options(scipen=5)
library(pander)
```
The LifeInsuranceContracts package provides a full-featured framework to model classical life insurance contracts (non-unit linked). This is typically sufficient to implement simple example calculations or validate a single contract or tariff by a single individual.
However, when working for a company (eith from inside the company or as an external consultant), one typically wants the implementation to be nicely structured, easily available for the whole team and still have the chance to improve the implementation.
This can be achieved by encapsulating the company-specific tariff implementations
in an R package that provides and exports the individual products of the company.
The LifeInsuranceContracts package even provides an RStudio project template
to create a new skeleton of a company-specific implementation to use as the
foundation of such an implementation.
Once,
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment