Skip to content

Commit

Permalink
pre-render safety
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewphamilton committed Jun 8, 2024
1 parent 6d20027 commit 6cd03d0
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 67 deletions.
2 changes: 1 addition & 1 deletion R/grp_generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ reckonSlot <- function (x,
UseMethod("reckonSlot", x)
}
methods::setGeneric("reckonSlot")
#' Apply the renew method to a model module slot
#' Renew (set) the values of data in a module slot
#' @rdname renewSlot-methods
#' @description renewSlot() is a "setter" method that renews (sets) the value of a specified model module slot with either the value returned by applying the renew method to that slot (the default behaviour) or a supplied new value.
#' @param x A model module (an instance of a class that inherits from Ready4Module)
Expand Down
18 changes: 9 additions & 9 deletions data-raw/DATASET.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ source("data-raw/FUNCTIONS.R") # Required to manage conflicts
#dir.create("data-raw/examples")

x <- ready4fun::make_pkg_desc_ls(
pkg_title_1L_chr = "Implement Modular And Open-Source Health Economic Models" %>% tools::toTitleCase(),
pkg_desc_1L_chr = "Programming syntax, a template model module and tools to help maintain a modular and open-source health economic model's project documentation website.
These elements are the foundation for a prototype software framework to support replicable and transferable health economic models. The software framework is extended by other R libraries.
For detailed documentation about the framework and how to use it visit <https://www.ready4-dev.com/>. For a background to the methodological issues that the framework is attempting to help solve, see Hamilton et al. (2024) <doi:10.48550/arXiv.2310.14138>.",
pkg_title_1L_chr = "Develop And Use Modular Health Economic Models" %>% tools::toTitleCase(),
pkg_desc_1L_chr = "A template model module, tools to help find model modules derived from this template and a programming syntax to use these modules in health economic analyses.
These elements are the foundation for a prototype software framework for developing living and transferable models and using those models to undertake reproducible health economic analyses. The software framework is extended by other R libraries.
For detailed documentation about the framework and how to use it visit <https://www.ready4-dev.com/>. For a background to the methodological issues that the framework is attempting to help solve, see Hamilton et al. (2024) <doi:10.1007/s40273-024-01378-8>.",
authors_prsn = c(utils::person(
given = "Matthew",family = "Hamilton", email = "[email protected]", role = c("aut", "cre","cph"),
comment = c(ORCID = "0000-0001-7407-9194")
Expand Down Expand Up @@ -45,7 +45,7 @@ x <- x %>%
"get_methods() retrieves the ready4 methods that are available for a specified ready4 model module.",
"get_methods_tb() ingests 'methods_tb.RDS' (a table of methods associated with ready4 model modules) from a specified GitHub repository release.",
"get_modules_tb() ingests 'modules_tb.RDS' (a table of ready4 model modules) from a specified GitHub repository release.",
"make_code_releases_tbl() scrapes the details of a specified GitHub repository to generate a release history of ready libraries and executables. To work all repositories without any release need to be supplied using the 'exclude_chr' argument.", "make_datasts_tb() function searches the contents of a specified Dataverse collection and returns a summary of the the data collections it contains.",
"make_code_releases_tbl() scrapes the details of a specified GitHub repository to generate a release history of ready libraries and executables. To work all repositories without any release need to be supplied using the 'exclude_chr' argument.",
"make_datasts_tb() scrapes metadata from a specified Dataverse collection to create a summary table of its contents. The contents table can detail either subsidiary data collections or individual datasets from those subsidiary data collections.",
"make_ds_releases_tbl() scrapes metadata from Dataverse datasets for which a valid Digital Object Identifier (DOI) has been supplied to create a table summarising the entire release history of these datasets.",
"make_methods_tb() scrapes the documentation websites of all libraries of ready4 modules in a specified GitHub organisation and then creates a tabular summary of vignette examples of ready4 module methods.",
Expand Down Expand Up @@ -94,10 +94,10 @@ x <- write_self_srvc_pkg(x)
write_to_edit_workflow("pkgdown.yaml", consent_1L_chr = "Y") # In other packages, run for "test-coverage.yaml" as well.
#write_conditional_tags(c("devtools", "Hmisc", "readr", "readxl", "rmarkdown","usethis", "zen4R"), consent_1L_chr = "Y")
usethis::use_package("pkgload", type = "Suggests") # ??
readLines("README.md") %>% # update in ready4fun
#stringr::str_replace("https://app.codecov","https://codecov") %>% # port edit to ready4fun
gsub(pattern = "doi:10.48550/arXiv.([^&]+)", replacement = "https://arxiv.org/abs/\\1") %>%
writeLines(con = "README.md")
# readLines("README.md") %>% # update in ready4fun
# #stringr::str_replace("https://app.codecov","https://codecov") %>% # port edit to ready4fun
# gsub(pattern = "doi:10.48550/arXiv.([^&]+)", replacement = "https://arxiv.org/abs/\\1") %>%
# writeLines(con = "README.md")
# c(readLines("R/imp_fns.R"), # update in ready4fun
# " ",
# "#' NSE equals function",
Expand Down
2 changes: 1 addition & 1 deletion data-raw/generics/grp_generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ reckonSlot <- function (x,
UseMethod("reckonSlot", x)
}
methods::setGeneric("reckonSlot")
#' Apply the renew method to a model module slot
#' Renew (set) the values of data in a module slot
#' @rdname renewSlot-methods
#' @description renewSlot() is a "setter" method that renews (sets) the value of a specified model module slot with either the value returned by applying the renew method to that slot (the default behaviour) or a supplied new value.
#' @param x A model module (an instance of a class that inherits from Ready4Module)
Expand Down
2 changes: 1 addition & 1 deletion man/renewSlot-methods.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 10 additions & 11 deletions vignettes/V_01.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,24 @@ knitr::opts_chunk$set(echo = TRUE, warning = FALSE)
```{r results='hide', message=FALSE, warning=F}
library(ready4)
```
```{r echo=FALSE, eval=FALSE}
# The social, economic and service systems that shape population health are complex and thus can be challenging to model. Some health economic modelling projects may therefore be more tractable if broken into smaller tasks and advanced by multiple teams. Such phased and collaborative approaches can be facilitated by use of common frameworks for the development of computational models that are both open and modular. A model module can be used to model a discrete component of a health economic system.
```

## Motivation
A potentially attractive approach to modelling complex health systems is to begin with a relatively simple computational model and to progressively extend its scope and sophistication. Such an approach could be described as "modular" if it is possible to readily combine multiple discrete modelling projects (potentially developed by different modelling teams) that each independently describe distinct aspects of the system being modelled. The `ready4` package provides foundational elements of a software framework to support the development of modular and open-source computational health economic models using R.
A potentially attractive approach to modelling complex health systems is to begin with a relatively simple computational model and to progressively extend its scope and sophistication. Such an approach could be described as "modular" if it is possible to readily combine multiple discrete modelling projects (potentially developed by different modelling teams) that each independently describe distinct aspects of the system being modelled.

## Implementation
Modular model development is enabled by the [encapsulation and inheritance features of Object Oriented Programming (OOP)](https://www.ready4-dev.com/docs/framework/implementation/paradigm/object-oriented/). Specifically, `ready4` uses two of R's systems for implementing OOP - S3 and S4. An in-depth explanation of R's different class system is beyond the scope of this article, but is explored in [Hadley Wickham's Advanced R handbook](https://adv-r.hadley.nz/oo.html). However, it is useful to know some very high level information about S3 and S4 classes:
The `ready4` package provides foundational elements of a software framework to support the development of modular and open-source computational health economic models using R. Modular model development is enabled by the [encapsulation and inheritance features of Object Oriented Programming (OOP)](https://www.ready4-dev.com/docs/framework/implementation/paradigm/object-oriented/). Specifically, `ready4` uses two of R's systems for implementing OOP - S3 and S4. An in-depth explanation of R's different class system is beyond the scope of this article, but is explored in [Hadley Wickham's Advanced R handbook](https://adv-r.hadley.nz/oo.html). However, it is useful to know some very high level information about S3 and S4 classes:

- S4 classes are frequently said to be "formal", "strict" or "rigorous". The elements of an S4 class are called slots and the type of data that each slot is allowed to contain is specified in the class definition. An S4 class can be comprised of slots that contain different types of data (e.g. a slot that contains a character vector and another slot that contains tabular data).

- S3 classes are often described as "simple", "informal" and "flexible". S3 objects attach an attribute label to base type objects (e.g. a character vector, a data.frame, a list), which in turn is used to work out what methods should be applied to the class.

## Use

### ready4 Model Modules
As we use the term, a "model module" is comprised of both a data-structure (or "class") and algorithms (or "methods") that are associated with that data-structure. A model module can be used to model a discrete component of a health economic system. Model modules can be created from a template - the `ready4` package's `Ready4Module` class.
As we use the term, a "model module" is comprised of both a data-structure (an S4 class) and the algorithms (or "methods") that are associated with that data-structure. Model modules can be created from a template - the `ready4` package's `Ready4Module` class.

We can create an object (`X`) from the `Ready4Module` template using the following command.

Expand All @@ -39,7 +44,7 @@ However, if we inspect `X` we can see it is of limited use as it contains no dat
str(X)
```

The `Ready4Module` class is therefore not intended to be called directly. Instead, the purpose of `Ready4Module` is to be the parent class of other templates for creating model modules. `Ready4Module` and all of its child-classes (ie all model module templates) are "S4" classes.
The `Ready4Module` class is therefore not intended to be called directly. Instead, the purpose of `Ready4Module` is to be the parent class of other model modules. Prototype tools for authoring modules from this template are described [here](https://www.ready4-dev.com/docs/tutorials/authoring-modules/).

::: {.card .border-primary .mb-3 style="max-width: 20rem;"}

Expand All @@ -56,7 +61,7 @@ An instance of `Ready4Module` (or classes that inherit from `Ready4Module`) and
:::

### ready4 Model Sub-modules
In ready4, S3 classes are principally used to help define the structural properties of slots (array elements) of model modules and the methods that can be applied to these slots. S3 classes created for these purposes are called **sub-modules**.
In ready4, S3 classes are principally used to help define the structural properties of slots (elements) of model modules and the methods that can be applied to these slots. S3 classes created for these purposes are called **sub-modules**.

::: {.card .border-primary .mb-3 style="max-width: 20rem;"}

Expand All @@ -72,11 +77,5 @@ An instance of an informal (S3) class and its associated methods that describes,
:::
:::

### Module and Sub-module Methods
All methods associated with modules and sub-modules adopt [a common syntax](https://www.ready4-dev.com/docs/framework/implementation/syntax/). However, the algorithms implemented by each command in that syntax will vary depending on which module it is applied to. A limited number of methods are defined for the `Ready4Module` template which by default are inherited by all other module templates. Currently, the only methods defined for `Ready4Module` are [slot-methods](https://www.ready4-dev.com/docs/framework/implementation/syntax/#slot-generics-and-methods) and these can be itemised using the `get_methods` function.

```{r}
get_methods()
```

Developers using the extended ready4 software framework can use our [module authoring tools](https://www.ready4-dev.com/docs/framework/use/authoring-modules/) to add new methods or overwrite inherited default methods.
Loading

0 comments on commit 6cd03d0

Please sign in to comment.