Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package updates for v0.3.0 CRAN submission #410

Merged
merged 13 commits into from
Nov 21, 2024
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
^vignettes/*.orig$
^vignettes/figure$
^vignettes/articles$
^cran-comments\.md$
^CRAN-SUBMISSION$
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: epiparameter
Title: Library of Epidemiological Parameters with Helper Functions and
Classes
Version: 0.2.0.9000
Version: 0.3.0
Authors@R: c(
person("Joshua W.", "Lambert", , "joshua.lambert@lshtm.ac.uk", role = c("aut", "cre", "cph"),
comment = c(ORCID = "0000-0001-5218-3046")),
Expand All @@ -23,7 +23,8 @@ Authors@R: c(
comment = c(ORCID = "0000-0002-8587-7113"))
)
Description: Library of epidemiological parameters for infectious diseases
and a set of classes and helper functions.
extracted from the literature, and a set of classes and helper functions
for working with parameters.
License: MIT + file LICENSE
URL: https://github.com/epiverse-trace/epiparameter/,
https://epiverse-trace.github.io/epiparameter/
Expand Down
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# epiparameter (development version)
# epiparameter 0.3.0

The third minor release of the {epiparameter} R package contains a range of updates and improvements to the package. The principal aim of this release is to simplify, clarify and enhance the classes and class methods when working with epidemiological parameters in R.

Expand All @@ -10,7 +10,7 @@ This is the first version of {epiparameter} to be released on CRAN.

* The library of epidemiological parameters has been updated to include 3 new Chikungunya parameter entries. The Mpox parameters previously missing from the Guzzetta et al. entry have been added (#346 & #374).
* A `c()` method has been added for `<epiparameter>` and `<multi_epiparameter>` objects (#368).
* An `aggregate()` method has been added for `<multi_epiparameter>` to enable consensus distributions to be built utilising the mixture distribution class from [{distributional}](https://cran.r-project.org/web/packages/distributional/index.html) (#388).
* An `aggregate()` method has been added for `<multi_epiparameter>` to enable consensus distributions to be built utilising the mixture distribution class from [{distributional}](https://CRAN.R-project.org/package=distributional) (#388).
* Infrastructure has been added to the package to allow translations of messages/warnings/errors printed to the console. (@Bisaloo, #367).
* `convert_summary_stats_to_params()` can now convert from median and dispersion for a lognormal distribution (#378).
* The `data_dictionary.json` has been enhanced to improve validation of the library of epidemiological parameters (`parameters.json`) (#379).
Expand Down
1 change: 1 addition & 0 deletions R/accessors.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ get_parameters.epiparameter <- function(x, ...) {
params
}

#' @rdname get_parameters.epiparameter
#' @export
get_parameters.multi_epiparameter <- function(x, ...) {
params <- lapply(x, get_parameters)
Expand Down
2 changes: 2 additions & 0 deletions R/checkers.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ is_parameterised <- function(x, ...) {
#' @export
is_parameterized <- is_parameterised

#' @rdname is_parameterised
#' @export
is_parameterised.epiparameter <- function(x, ...) {
chkDots(...)
# probability distribution object
return(is.object(x$prob_distribution))
}

#' @rdname is_parameterised
#' @export
is_parameterised.multi_epiparameter <- function(x, ...) {
chkDots(...)
Expand Down
42 changes: 25 additions & 17 deletions R/coercion.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
#'
#' @return A [function] object.
#' @export
#'
#' @examples
#' ep <- epiparameter_db(single_epiparameter = TRUE)
#' # by default it will convert to a density function
#' f <- as.function(ep)
#' # use function
#' f(10)
#'
#' f <- as.function(ep, func_type = "cdf")
#' f(10)
as.function.epiparameter <- function(x,
func_type = c(
"density", "cdf", "generate", "quantile"
Expand Down Expand Up @@ -53,6 +63,10 @@ as.function.epiparameter <- function(x,
#'
#' @return A `<data.frame>` with a single row.
#' @export
#'
#' @examples
#' ep <- epiparameter_db(single_epiparameter = TRUE)
#' as.data.frame(ep)
as.data.frame.epiparameter <- function(x, ...) {
chkDots(...)
# check object as could be invalidated by user
Expand Down Expand Up @@ -82,6 +96,10 @@ as.data.frame.epiparameter <- function(x, ...) {
#'
#' @return A `<data.frame>` with as many rows as length of input list.
#' @export
#'
#' @examples
#' db <- epiparameter_db()
#' as.data.frame(db)
as.data.frame.multi_epiparameter <- function(x, ...) {
chkDots(...)
do.call(rbind, lapply(x, as.data.frame))
Expand Down Expand Up @@ -133,6 +151,11 @@ as_epiparameter <- function(x, ...) {
#'
#' @inherit epiparameter_db return
#' @export
#'
#' @examples
#' ep <- epiparameter_db(single_epiparameter = TRUE)
#' df <- as.data.frame(ep)
#' ep <- as_epiparameter(df)
as_epiparameter.data.frame <- function(x, ...) {
if (is_epiparameter_df(x)) {
epiparameter <- .epiparameter_df_to_epiparameter(x, ...)
Expand Down Expand Up @@ -189,19 +212,12 @@ is_epiparameter_df <- function(x) {
#' @inherit epiparameter return
#' @keywords internal
.epiparameter_df_to_epiparameter <- function(x, ...) { # nolint object_length_linter
# extract probability distribution from list and extract parameters
# and truncation if available
prob_dist <- x$prob_distribution[[1]]
if (inherits(prob_dist, "distribution")) {
prob_distribution_params <- unlist(
distributional::parameters(x$prob_distribution[[1]])
)
}
if (identical(family(prob_dist), "truncated")) {
truncation <- distributional::parameters(x$prob_distribution)$upper
} else {
truncation <- NA_real_
}
# create uncertainty list of parameters if not provided
if (all(unlist(lapply(x$uncertainty$uncertainty, is.na)))) {
uncertainty <- x$uncertainty$uncertainty
Expand All @@ -212,23 +228,15 @@ is_epiparameter_df <- function(x) {
)
}

# remove <AsIs> from citation
class(x$citation) <- setdiff(class(x$citation), "AsIs")

# return <epiparameter> from class constructor
epiparameter(
disease = x$disease,
pathogen = x$pathogen,
epi_name = x$epi_name,
prob_distribution = create_prob_distribution(
prob_distribution = family(x$prob_distribution[[1]]),
prob_distribution_params = prob_distribution_params,
discretise = inherits(x$prob_distribution[[1]], "distcrete"),
truncation = truncation
),
prob_distribution = prob_dist,
uncertainty = uncertainty,
summary_stats = x$summary_stats$summary_stats,
citation = x$citation,
citation = x$citation[[1]],
metadata = x$metadata,
method_assess = x$method_assess,
notes = x$notes
Expand Down
17 changes: 17 additions & 0 deletions R/epiparameter.R
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ epiparameter <- function(disease,
#' (errors when invalid `<epiparameter>` object is provided).
#'
#' @export
#'
#' @examples
#' ep <- epiparameter_db(single_epiparameter = TRUE)
#' assert_epiparameter(ep)
#'
#' # example with invalid <epiparameter>
#' ep$disease <- NULL
#' try(assert_epiparameter(ep))
assert_epiparameter <- function(x) {
msg <- .validate_epiparameter(x)
if (length(msg) > 0) {
Expand All @@ -320,6 +328,14 @@ assert_epiparameter <- function(x) {
#' @return A boolean `logical` whether the object is a valid `<epiparameter>`
#' object (prints message when invalid `<epiparameter>` object is provided).
#' @export
#'
#' @examples
#' ep <- epiparameter_db(single_epiparameter = TRUE)
#' test_epiparameter(ep)
#'
#' # example with invalid <epiparameter>
#' ep$disease <- NULL
#' test_epiparameter(ep)
test_epiparameter <- function(x) {
msg <- .validate_epiparameter(x)
if (length(msg) > 0) {
Expand Down Expand Up @@ -987,6 +1003,7 @@ c.epiparameter <- function(...) {
ep_list
}

#' @rdname c.epiparameter
#' @export
c.multi_epiparameter <- function(...) {
c.epiparameter(...)
Expand Down
4 changes: 3 additions & 1 deletion R/parameter_tbl.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
#' @param multi_epiparameter Either an `<epiparameter>` object or a list of
#' `<epiparameter>` objects.
#'
#' @author Joshua W. Lambert, Adam Kucharski
#' @return A `<parameter_tbl>` object which is a subclass of `<data.frame>`.
#' @export
#' @author Joshua W. Lambert, Adam Kucharski
#'
#' @examples
#' epiparameter_list <- epiparameter_db(disease = "COVID-19")
#' parameter_tbl(multi_epiparameter = epiparameter_list)
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
10 changes: 8 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ knitr::opts_chunk$set(

## Installation

The easiest way to install the development version of `{epiparameter}` is to use the `{pak}` package:
The package can be installed from CRAN using:

``` r
install.packages("epiparameter")
```

The development version of `{epiparameter}` can be installed from [GitHub](https://github.com/epiverse-trace/epiparameter) using the `{pak}` package:

``` r
# check whether {pak} is installed
Expand All @@ -41,7 +47,7 @@ pak::pak("epiverse-trace/epiparameter")

Alternatively, install pre-compiled binaries from [the Epiverse TRACE R-universe](https://epiverse-trace.r-universe.dev/epiparameter)

```r
``` r
install.packages("epiparameter", repos = c("https://epiverse-trace.r-universe.dev", "https://cloud.r-project.org"))
```

Expand Down
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ Medicine](https://www.lshtm.ac.uk/) as part of

## Installation

The easiest way to install the development version of `{epiparameter}`
is to use the `{pak}` package:
The package can be installed from CRAN using:

``` r
install.packages("epiparameter")
```

The development version of `{epiparameter}` can be installed from
[GitHub](https://github.com/epiverse-trace/epiparameter) using the
`{pak}` package:

``` r
# check whether {pak} is installed
Expand Down Expand Up @@ -272,7 +279,7 @@ citation("epiparameter")
#> Epidemiological Parameters with Helper Functions and Classes_.
#> doi:10.5281/zenodo.11110881
#> <https://doi.org/10.5281/zenodo.11110881>,
#> <https://epiverse-trace.github.io/epiparameter>.
#> <https://epiverse-trace.github.io/epiparameter/>.
#>
#> A BibTeX entry for LaTeX users is
#>
Expand All @@ -281,6 +288,6 @@ citation("epiparameter")
#> author = {Joshua W. Lambert and Adam Kucharski and Carmen Tamayo},
#> year = {2024},
#> doi = {10.5281/zenodo.11110881},
#> url = {https://epiverse-trace.github.io/epiparameter},
#> url = {https://epiverse-trace.github.io/epiparameter/},
#> }
```
5 changes: 5 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## R CMD check results

0 errors | 0 warnings | 1 note

* This is a new release.
2 changes: 1 addition & 1 deletion inst/CITATION
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ bibentry(
author = author,
year = date,
doi = "10.5281/zenodo.11110881",
url = "https://epiverse-trace.github.io/epiparameter"
url = "https://epiverse-trace.github.io/epiparameter/"
)
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ medRxiv
MERS
monkeypox
mpox
Mpox
ORCID
parameterisations
parameterised
Expand Down
4 changes: 4 additions & 0 deletions man/as.data.frame.epiparameter.Rd

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

4 changes: 4 additions & 0 deletions man/as.data.frame.multi_epiparameter.Rd

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

10 changes: 10 additions & 0 deletions man/as.function.epiparameter.Rd

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

5 changes: 5 additions & 0 deletions man/as_epiparameter.data.frame.Rd

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

8 changes: 8 additions & 0 deletions man/assert_epiparameter.Rd

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

3 changes: 3 additions & 0 deletions man/c.epiparameter.Rd

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

2 changes: 1 addition & 1 deletion man/epiparameter-package.Rd

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

3 changes: 3 additions & 0 deletions man/get_parameters.epiparameter.Rd

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

6 changes: 6 additions & 0 deletions man/is_parameterised.Rd

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

Loading