diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000..0563713
Binary files /dev/null and b/.DS_Store differ
diff --git a/.Rproj.user/C3EAF566/cpp-definition-cache b/.Rproj.user/C3EAF566/cpp-definition-cache
new file mode 100644
index 0000000..0637a08
--- /dev/null
+++ b/.Rproj.user/C3EAF566/cpp-definition-cache
@@ -0,0 +1 @@
+[]
\ No newline at end of file
diff --git a/.Rproj.user/C3EAF566/pcs/debug-breakpoints.pper b/.Rproj.user/C3EAF566/pcs/debug-breakpoints.pper
new file mode 100644
index 0000000..4893a8a
--- /dev/null
+++ b/.Rproj.user/C3EAF566/pcs/debug-breakpoints.pper
@@ -0,0 +1,5 @@
+{
+ "debugBreakpointsState": {
+ "breakpoints": []
+ }
+}
\ No newline at end of file
diff --git a/.Rproj.user/C3EAF566/pcs/files-pane.pper b/.Rproj.user/C3EAF566/pcs/files-pane.pper
new file mode 100644
index 0000000..e7c1f67
--- /dev/null
+++ b/.Rproj.user/C3EAF566/pcs/files-pane.pper
@@ -0,0 +1,9 @@
+{
+ "sortOrder": [
+ {
+ "columnIndex": 2,
+ "ascending": true
+ }
+ ],
+ "path": "~/Documents/BSC/Fundings/MSCA/Development/Analysis/epidesc"
+}
\ No newline at end of file
diff --git a/.Rproj.user/C3EAF566/pcs/packages-pane.pper b/.Rproj.user/C3EAF566/pcs/packages-pane.pper
new file mode 100644
index 0000000..6efb098
--- /dev/null
+++ b/.Rproj.user/C3EAF566/pcs/packages-pane.pper
@@ -0,0 +1,7 @@
+{
+ "installOptions": {
+ "installFromRepository": true,
+ "libraryPath": "/home/rmartins/R/x86_64-pc-linux-gnu-library/4.6",
+ "installDependencies": true
+ }
+}
\ No newline at end of file
diff --git a/.Rproj.user/C3EAF566/pcs/source-pane.pper b/.Rproj.user/C3EAF566/pcs/source-pane.pper
new file mode 100644
index 0000000..b074a4f
--- /dev/null
+++ b/.Rproj.user/C3EAF566/pcs/source-pane.pper
@@ -0,0 +1,3 @@
+{
+ "activeTab": 1
+}
\ No newline at end of file
diff --git a/.Rproj.user/C3EAF566/pcs/windowlayoutstate.pper b/.Rproj.user/C3EAF566/pcs/windowlayoutstate.pper
new file mode 100644
index 0000000..07e8221
--- /dev/null
+++ b/.Rproj.user/C3EAF566/pcs/windowlayoutstate.pper
@@ -0,0 +1,14 @@
+{
+ "left": {
+ "splitterpos": 198,
+ "topwindowstate": "NORMAL",
+ "panelheight": 596,
+ "windowheight": 634
+ },
+ "right": {
+ "splitterpos": 380,
+ "topwindowstate": "NORMAL",
+ "panelheight": 596,
+ "windowheight": 634
+ }
+}
\ No newline at end of file
diff --git a/.Rproj.user/C3EAF566/pcs/workbench-pane.pper b/.Rproj.user/C3EAF566/pcs/workbench-pane.pper
new file mode 100644
index 0000000..c38a0b3
--- /dev/null
+++ b/.Rproj.user/C3EAF566/pcs/workbench-pane.pper
@@ -0,0 +1,5 @@
+{
+ "TabSet1": 4,
+ "TabSet2": 0,
+ "TabZoom": {}
+}
\ No newline at end of file
diff --git a/.Rproj.user/C3EAF566/persistent-state b/.Rproj.user/C3EAF566/persistent-state
new file mode 100644
index 0000000..6b3342f
--- /dev/null
+++ b/.Rproj.user/C3EAF566/persistent-state
@@ -0,0 +1,8 @@
+build-last-errors="[]"
+build-last-errors-base-dir="~/Documents/BSC/Fundings/MSCA/Development/Analysis/epidesc/"
+build-last-outputs="[{\"type\":0,\"output\":\"==> R CMD INSTALL --preclean --no-multiarch --with-keep.source epidesc\\n\\n\"},{\"type\":1,\"output\":\"* installing to library ‘/home/rmartins/R/x86_64-pc-linux-gnu-library/4.6/_build’\\n\"},{\"type\":1,\"output\":\"* installing *source* package ‘epidesc’ ...\\n\"},{\"type\":1,\"output\":\"** this is package ‘epidesc’ version ‘0.1.0’\\n\"},{\"type\":1,\"output\":\"** using staged installation\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** R\\n\"},{\"type\":1,\"output\":\"** data\\n\"},{\"type\":1,\"output\":\"*** moving datasets to lazyload DB\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** inst\\n\"},{\"type\":1,\"output\":\"** byte-compile and prepare package for lazy loading\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** help\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"*** installing help indices\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** building package indices\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** installing vignettes\\n\"},{\"type\":1,\"output\":\"** testing if installed package can be loaded from temporary location\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** testing if installed package can be loaded from final location\\n\"},{\"type\":1,\"output\":\"\"},{\"type\":1,\"output\":\"** testing if installed package keeps a record of temporary installation path\\n\"},{\"type\":1,\"output\":\"* DONE (epidesc)\\n\"},{\"type\":1,\"output\":\"\"}]"
+compile_pdf_state="{\"tab_visible\":false,\"running\":false,\"target_file\":\"\",\"output\":\"\",\"errors\":[]}"
+files.monitored-path=""
+find-in-files-state="{\"handle\":\"\",\"input\":\"\",\"path\":\"\",\"regex\":false,\"ignoreCase\":false,\"results\":{\"file\":[],\"line\":[],\"lineValue\":[],\"matchOn\":[],\"matchOff\":[],\"replaceMatchOn\":[],\"replaceMatchOff\":[]},\"running\":false,\"replace\":false,\"preview\":false,\"gitFlag\":false,\"replacePattern\":\"\"}"
+imageDirtyState="1"
+saveActionState="0"
diff --git a/.Rproj.user/C3EAF566/rmd-outputs b/.Rproj.user/C3EAF566/rmd-outputs
new file mode 100644
index 0000000..3f2ff2d
--- /dev/null
+++ b/.Rproj.user/C3EAF566/rmd-outputs
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/.Rproj.user/C3EAF566/saved_source_markers b/.Rproj.user/C3EAF566/saved_source_markers
new file mode 100644
index 0000000..2b1bef1
--- /dev/null
+++ b/.Rproj.user/C3EAF566/saved_source_markers
@@ -0,0 +1 @@
+{"active_set":"","sets":[]}
\ No newline at end of file
diff --git a/.Rproj.user/C3EAF566/sources/prop/1BE58D88 b/.Rproj.user/C3EAF566/sources/prop/1BE58D88
new file mode 100644
index 0000000..ff81466
--- /dev/null
+++ b/.Rproj.user/C3EAF566/sources/prop/1BE58D88
@@ -0,0 +1,8 @@
+{
+ "source_window_id": "",
+ "Source": "Source",
+ "last_setup_crc32": "9f14958afd5dcac3",
+ "cursorPosition": "104,0",
+ "scrollLine": "0",
+ "chunk_output_type": "console"
+}
\ No newline at end of file
diff --git a/.Rproj.user/C3EAF566/sources/prop/1DBC1031 b/.Rproj.user/C3EAF566/sources/prop/1DBC1031
new file mode 100644
index 0000000..bb27690
--- /dev/null
+++ b/.Rproj.user/C3EAF566/sources/prop/1DBC1031
@@ -0,0 +1,4 @@
+{
+ "source_window_id": "",
+ "Source": "Source"
+}
\ No newline at end of file
diff --git a/.Rproj.user/C3EAF566/sources/prop/51583C41 b/.Rproj.user/C3EAF566/sources/prop/51583C41
new file mode 100644
index 0000000..bb27690
--- /dev/null
+++ b/.Rproj.user/C3EAF566/sources/prop/51583C41
@@ -0,0 +1,4 @@
+{
+ "source_window_id": "",
+ "Source": "Source"
+}
\ No newline at end of file
diff --git a/.Rproj.user/C3EAF566/sources/prop/66776074 b/.Rproj.user/C3EAF566/sources/prop/66776074
new file mode 100644
index 0000000..bb27690
--- /dev/null
+++ b/.Rproj.user/C3EAF566/sources/prop/66776074
@@ -0,0 +1,4 @@
+{
+ "source_window_id": "",
+ "Source": "Source"
+}
\ No newline at end of file
diff --git a/.Rproj.user/C3EAF566/sources/prop/784AC70C b/.Rproj.user/C3EAF566/sources/prop/784AC70C
new file mode 100644
index 0000000..fb9efb7
--- /dev/null
+++ b/.Rproj.user/C3EAF566/sources/prop/784AC70C
@@ -0,0 +1,6 @@
+{
+ "source_window_id": "",
+ "Source": "Source",
+ "cursorPosition": "70,26",
+ "scrollLine": "56"
+}
\ No newline at end of file
diff --git a/.Rproj.user/C3EAF566/sources/prop/90C6E5A4 b/.Rproj.user/C3EAF566/sources/prop/90C6E5A4
new file mode 100644
index 0000000..c551578
--- /dev/null
+++ b/.Rproj.user/C3EAF566/sources/prop/90C6E5A4
@@ -0,0 +1,11 @@
+{
+ "source_window_id": "",
+ "Source": "Source",
+ "rmdVisualMode": "true",
+ "rmdVisualCollapsedChunks": "",
+ "rmdVisualModeLocation": "1693:729.1428833007812",
+ "rmdVisualWrapConfigured": "true",
+ "docOutlineVisible": "0",
+ "cursorPosition": "0,0",
+ "scrollLine": "0"
+}
\ No newline at end of file
diff --git a/.Rproj.user/C3EAF566/sources/prop/A656A517 b/.Rproj.user/C3EAF566/sources/prop/A656A517
new file mode 100644
index 0000000..bb27690
--- /dev/null
+++ b/.Rproj.user/C3EAF566/sources/prop/A656A517
@@ -0,0 +1,4 @@
+{
+ "source_window_id": "",
+ "Source": "Source"
+}
\ No newline at end of file
diff --git a/.Rproj.user/C3EAF566/sources/prop/D2D3A6FF b/.Rproj.user/C3EAF566/sources/prop/D2D3A6FF
new file mode 100644
index 0000000..c2c06a0
--- /dev/null
+++ b/.Rproj.user/C3EAF566/sources/prop/D2D3A6FF
@@ -0,0 +1,6 @@
+{
+ "source_window_id": "",
+ "Source": "Source",
+ "cursorPosition": "23,15",
+ "scrollLine": "17"
+}
\ No newline at end of file
diff --git a/.Rproj.user/C3EAF566/sources/prop/FB2C4294 b/.Rproj.user/C3EAF566/sources/prop/FB2C4294
new file mode 100644
index 0000000..6a49ac6
--- /dev/null
+++ b/.Rproj.user/C3EAF566/sources/prop/FB2C4294
@@ -0,0 +1,6 @@
+{
+ "source_window_id": "",
+ "Source": "Source",
+ "cursorPosition": "8,25",
+ "scrollLine": "1"
+}
\ No newline at end of file
diff --git a/.Rproj.user/C3EAF566/sources/prop/INDEX b/.Rproj.user/C3EAF566/sources/prop/INDEX
new file mode 100644
index 0000000..2d69f3a
--- /dev/null
+++ b/.Rproj.user/C3EAF566/sources/prop/INDEX
@@ -0,0 +1,9 @@
+~%2FDocuments%2FBSC%2FFundings%2FMSCA%2FDevelopment%2FAnalysis%2Fepidesc%2FLICENSE.md="784AC70C"
+~%2FDocuments%2FBSC%2FFundings%2FMSCA%2FDevelopment%2FAnalysis%2Fepidesc%2FNEWS.md="A656A517"
+~%2FDocuments%2FBSC%2FFundings%2FMSCA%2FDevelopment%2FAnalysis%2Fepidesc%2FR%2Fdesc-cases.R="FB2C4294"
+~%2FDocuments%2FBSC%2FFundings%2FMSCA%2FDevelopment%2FAnalysis%2Fepidesc%2FR%2Fdesc-peak.R="66776074"
+~%2FDocuments%2FBSC%2FFundings%2FMSCA%2FDevelopment%2FAnalysis%2Fepidesc%2FR%2Fdesc_list.R="D2D3A6FF"
+~%2FDocuments%2FBSC%2FFundings%2FMSCA%2FDevelopment%2FAnalysis%2Fepidesc%2FREADME.md="90C6E5A4"
+~%2FDocuments%2FBSC%2FFundings%2FMSCA%2FDevelopment%2FAnalysis%2Fepidesc%2Fman%2Fdesc_Cmed.Rd="51583C41"
+~%2FDocuments%2FBSC%2FFundings%2FMSCA%2FDevelopment%2FAnalysis%2Fepidesc%2Ftests%2Ftestthat.R="1DBC1031"
+~%2FDocuments%2FBSC%2FFundings%2FMSCA%2FDevelopment%2FAnalysis%2Fepidesc%2Fvignettes%2Fepidesc.Rmd="1BE58D88"
diff --git a/.Rproj.user/C3EAF566/sources/session-9f14958a/073730A4-contents b/.Rproj.user/C3EAF566/sources/session-9f14958a/073730A4-contents
new file mode 100644
index 0000000..7d50d42
--- /dev/null
+++ b/.Rproj.user/C3EAF566/sources/session-9f14958a/073730A4-contents
@@ -0,0 +1,20 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/desc-cases.R
+\name{desc_Cmed}
+\alias{desc_Cmed}
+\title{Cmed}
+\usage{
+desc_Cmed(df, x)
+}
+\arguments{
+\item{df}{A data.frame consisting of 52 rows (1 year) for a single spatial
+unit with columns 'time' (epiyearweek), 'cases', 'epiweek' and 'epiyear'.}
+
+\item{x}{Number of cases.}
+}
+\value{
+The computed Cmed epidescriptor.
+}
+\description{
+Median duration in consecutive weeks with at least 'x' cases.
+}
diff --git a/.Rproj.user/C3EAF566/sources/session-9f14958a/59A30531-contents b/.Rproj.user/C3EAF566/sources/session-9f14958a/59A30531-contents
new file mode 100644
index 0000000..fcb91e5
--- /dev/null
+++ b/.Rproj.user/C3EAF566/sources/session-9f14958a/59A30531-contents
@@ -0,0 +1,83 @@
+# epidesc
+
+
+
+[](https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
+
+
+
+## Overview
+
+
+
+The R package **epidesc** provides the tools to easily compute a series of epidemiological indicators to characterise different transmission profiles of infectious diseases. The work is based on the publication How heterogeneous is the dengue transmission profile in Brazil? A study in six Brazilian states () published in PLoS Neglected Tropical Diseases by Iasmim Ferreira de Almeida, Raquel Martins Lana and Cláudia Torres Codeço in 2022.
+
+The **epidesc** pipeline to compute the indicators is the following: \* Formatting dates in *epiyearweek* format. \* Choosing descriptors and its parameters from the catalogue. \* Compute descriptors.
+
+In order to work, the data used to compute the descriptors needs to have a few simple requirements: \* The input data has to be a data.frame with the cases and spatiotemporal identifiers. \* The data needs to be weekly with dates in Date format. \* If an incidence descriptor is required, the population at risk also needs to be provided.
+
+To find out more, please have a look at the package vignette.
+
+## Included descriptors
+
+The current version of the package includes the following descriptors:
+
+``` r
+library("epidesc")
+knitr::kable(desc_list())
+```
+
+| class | fun | description | param1 | param2 |
+|:---|:---|:---|:---|:---|
+| Peak | Ap | Maximum cases peak | | |
+| Peak | Tp | Week where the maximum peak occurred | | |
+| Period with cases | Cnf | Frequency of periods of consecutive 'n' weeks or longer with at least 'x' cases | n | x |
+| Period with cases | Cmax | Maximum duration in consecutive weeks with at least 'x' cases | x | |
+| Period with cases | Cmed | Median duration in consecutive weeks with at least 'x' cases | x | |
+| Period with cases | Isof | Number of weeks with isolated cases | | |
+| Period with cases | p | Proportion of weeks with at least 'x' cases | x | |
+| Period without cases | Cwf | Frequency of periods of consecutive weeks with at least 'n' weeks without cases. | n | |
+| Period without cases | Cwmax | Maximum duration in consecutive weeks without cases | | |
+| Period without cases | Cwmed | Median duration in consecutive weeks without cases | | |
+| Incidence | Inc | Annual incidence per 'p' persons | p | |
+
+## Contributions
+
+We are very interested in keep expanding **epidesc** with new descriptors and we are open to contributions. If would like to contribute, please open an issue with your idea or get in touch with Raquel Martins Lana ([raquel.lana\@bsc.es](mailto:raquel.lana@bsc.es){.email}, [raquelmlana\@gmail.com](mailto:raquelmlana@gmail.com){.email}) or Carles Milà ([carles.milagarcia\@bsc.es](mailto:carles.milagarcia@bsc.es){.email}) to discuss its inclusion.
+
+## Installation
+
+`epidesc` is still in development and not on CRAN. You can install the development version of epidesc as follows:
+
+``` r
+pak::pak("https://github.com/BSC-ES/epidesc.git")
+```
+
+## Package authors
+
+[**Raquel Martins Lana, PhD**](https://www.bsc.es/martins-lana-raquel)
\
+Barcelona Supercomputing Center
+
+[**Carles Milà, PhD**](https://www.bsc.es/mila-garcia-carles)
\
+Barcelona Supercomputing Center
+
+**Iasmin Ferreira de Almeida, PhD**
\
+Getulio Vargas Foundation (FGV)
+
+**Claudia Torres Codeço, PhD**
\
+Oswaldo Cruz Foundation (Fiocruz)
+
+[**Daniela Lührsen, MSc**](https://www.bsc.es/luhrsen-daniela-sofie)
\
+Barcelona Supercomputing Center
+
+**Diego Ricardo Xavier Silva, PhD**
\
+Oswaldo Cruz Foundation (Fiocruz)
+
+**Christovam Barcellos, PhD**
\
+Oswaldo Cruz Foundation (Fiocruz)
+
+**Raphael Saldanha, PhD**
\
+Oswaldo Cruz Foundation (Fiocruz)
+
+[**Rachel Lowe, PhD**](https://www.bsc.es/lowe-rachel)
\
+Barcelona Supercomputing Center
diff --git a/.Rproj.user/C3EAF566/sources/session-9f14958a/64442212-contents b/.Rproj.user/C3EAF566/sources/session-9f14958a/64442212-contents
new file mode 100644
index 0000000..4f95bb4
--- /dev/null
+++ b/.Rproj.user/C3EAF566/sources/session-9f14958a/64442212-contents
@@ -0,0 +1,99 @@
+#' Cnf
+#'
+#' @description Frequency of periods of consecutive 'n' weeks or longer with at
+#' least 'x' cases.
+#'
+#' @param df A data.frame consisting of 52 rows (1 year) for a single spatial
+#' unit with columns 'time' (epiyearweek), 'cases', 'epiweek' and 'epiyear'.
+#' @param n Number of consecutive weeks.
+#' @param x Number of cases.
+#'
+#' @returns The computed Cnf epidescriptor.
+#' @export
+desc_Cnf <- function(df, n, x) {
+ res <- nseq::trle_cond(df$cases, a_op = "gte", a = n, b_op = "gte", b = x)
+
+ return(res)
+}
+
+#' Cmax
+#'
+#' @description Maximum duration in consecutive weeks with at least 'x' cases.
+#'
+#' @param df A data.frame consisting of 52 rows (1 year) for a single spatial
+#' unit with columns 'time' (epiyearweek), 'cases', 'epiweek' and 'epiyear'.
+#' @param x Number of cases.
+#'
+#' @returns The computed Cmax epidescriptor.
+#' @export
+desc_Cmax <- function(df, x) {
+ res <- nseq::trle_cond_stat(df$cases, b_op = "gte", b = x, stat = "max")
+
+ # If no sequences are found
+ if (is.na(res)) {
+ res <- 0
+ }
+
+ return(res)
+}
+
+#' Cmed
+#'
+#' @description Median duration in consecutive weeks with at least 'x' cases.
+#'
+#' @param df A data.frame consisting of 52 rows (1 year) for a single spatial
+#' unit with columns 'time' (epiyearweek), 'cases', 'epiweek' and 'epiyear'.
+#' @param x Number of cases.
+#'
+#' @returns The computed Cmed epidescriptor.
+#' @export
+desc_Cmed <- function(df, x) {
+ res <- nseq::trle_cond_stat(df$cases, b_op = "gte", b = x, stat = "median")
+
+ # If no sequences are found
+ if (is.na(res)) {
+ res <- 0
+ }
+
+ return(res)
+}
+
+#' Isof
+#'
+#' @description Number of weeks with isolated cases, i.e. weeks with 0 cases
+#' both in the previous and following week.
+#'
+#' @param df A data.frame consisting of 52 rows (1 year) for a single spatial
+#' unit with columns 'time' (epiyearweek), 'cases', 'epiweek' and 'epiyear'.
+#'
+#' @returns The computed Isof epidescriptor.
+#' @export
+desc_Isof <- function(df) {
+ res <- nseq::trle_cond(
+ df$cases,
+ a_op = "e",
+ a = 1,
+ b_op = "gt",
+ b = 0,
+ isolated = TRUE
+ )
+
+ return(res)
+}
+
+#' p
+#'
+#' @description Proportion fo weeks with at least 'x' cases.
+#'
+#' @param df A data.frame consisting of 52 rows (1 year) for a single spatial
+#' unit with columns 'time' (epiyearweek), 'cases', 'epiweek' and 'epiyear'.
+#' @param x Number of cases.
+#'
+#' @returns The computed p epidescriptor.
+#' @export
+desc_p <- function(df, x) {
+ res <- df$cases >= x
+ res <- sum(res) / length(res)
+
+ return(res)
+}
diff --git a/.Rproj.user/C3EAF566/sources/session-9f14958a/9476C86A b/.Rproj.user/C3EAF566/sources/session-9f14958a/9476C86A
new file mode 100644
index 0000000..25089dd
--- /dev/null
+++ b/.Rproj.user/C3EAF566/sources/session-9f14958a/9476C86A
@@ -0,0 +1,28 @@
+{
+ "id": "9476C86A",
+ "path": "~/Documents/BSC/Fundings/MSCA/Development/Analysis/epidesc/vignettes/epidesc.Rmd",
+ "project_path": "vignettes/epidesc.Rmd",
+ "type": "r_markdown",
+ "hash": "0",
+ "contents": "",
+ "dirty": false,
+ "created": 1784745328559.0,
+ "source_on_save": false,
+ "relative_order": 2,
+ "properties": {
+ "source_window_id": "",
+ "Source": "Source",
+ "last_setup_crc32": "9f14958afd5dcac3",
+ "cursorPosition": "104,0",
+ "scrollLine": "0",
+ "chunk_output_type": "console"
+ },
+ "folds": "",
+ "lastKnownWriteTime": 1784745372,
+ "encoding": "UTF-8",
+ "collab_server": "",
+ "source_window": "",
+ "last_content_update": 1784745372,
+ "read_only": false,
+ "read_only_alternatives": []
+}
\ No newline at end of file
diff --git a/.Rproj.user/C3EAF566/sources/session-9f14958a/9476C86A-contents b/.Rproj.user/C3EAF566/sources/session-9f14958a/9476C86A-contents
new file mode 100644
index 0000000..4b80d3f
--- /dev/null
+++ b/.Rproj.user/C3EAF566/sources/session-9f14958a/9476C86A-contents
@@ -0,0 +1,118 @@
+---
+title: "Introduction to epidesc"
+output:
+ rmarkdown::html_vignette:
+ toc: true
+vignette: >
+ %\VignetteIndexEntry{Introduction to epidesc}
+ %\VignetteEngine{knitr::rmarkdown}
+ %\VignetteEncoding{UTF-8}
+---
+
+```{r, include = FALSE}
+knitr::opts_chunk$set(
+ collapse = TRUE,
+ comment = "#>"
+)
+```
+
+# Overview
+
+The R package `epidesc` provides the tools to easily compute a series of epidemiological indicators to characterise different transmission profiles of infectious diseases. The work is based on the publication [How heterogeneous is the dengue transmission profile in Brazil? A study in six Brazilian states](https://doi.org/10.1371/journal.pntd.0010746) published in PLOS neglected tropical diseases by Iasmim Ferreira de Almeida, Raquel Martins Lana and Cláudia Torres Codeço in 2022.
+
+While we include all the indicators contained in the original publication, `epidesc` aims to expand this list of indicators, welcoming contributions from researchers (please open and issue and we'll discuss!).
+
+# Usage
+
+To show the functionality of the package, we load weekly dengue data for municipalities in Rio de Janeiro.
+
+```{r setup}
+library(epidesc)
+library(knitr)
+
+data("dengueRio")
+head(dengueRio)
+```
+
+## Data requirements
+
+`epidesc` has a few simple data requirements:
+
+1. The input data has to be a data.frame with the cases and spatiotemporal identifiers. In our sample data, these would be the columns *casos* (dengue cases), *date* (temporal identifier), and *regional_geocode* (spatial identifier).
+2. The data needs to be weekly with dates in `Date` format.
+3. The time series needs to be regular, i.e. 7 days between consecutive observations.
+4. If an incidence descriptor is required, the population at risk also needs to be provided.
+
+Don't worry though, if any of these aren't met, the package function will throw error messages to indicate to you what's happening!
+
+## Formatting dates
+
+The only required pre-processing step is to convert the dates into epidemiological yearweek format: yyyyww. We can easily do so by using the function `epiyearweek` as follows.
+Note that Brazilian epidemiological weeks start on a Sunday:
+
+```{r}
+dengue <- dengueRio
+dengue$yearweek <- epiyearweek(dengue$date, start = "Sunday")
+head(dengue)
+```
+
+## Descriptor list
+
+To see the list of available descriptors and their required parameters, we can use the function `desc_list()`:
+
+```{r, eval = FALSE}
+desc_list()
+```
+
+```{r, echo=FALSE}
+kable(desc_list())
+```
+
+In this table we can see the class of each indicator, its function name, description, and required parameters. This is information we will need when we specify which descriptors we want to compute.
+
+## Computing descriptors
+
+The first step when computing the descriptors is to decide which of them to compute and the values of the parameters. In out case, we are interested in computing the following indicators:
+
+* *Ap*
+* *Cmax* with 'x' equal to 3 and 6
+* *Inc* for 100,000 persons
+
+To compute these indicators, we need to pass a nested list to the function `desc_year`. In the first level we state the output names of the descriptors that we want to use, and in the second level we specify the name of the function `fun` as in the table above as well as the parameters (`x`, `n` or `p` depending on the descriptor):
+
+```{r}
+descriptors <- list(
+ Ap = list(fun = "Ap"),
+ Cmax3 = list(fun = "Cmax", x = 3),
+ Cmax6 = list(fun = "Cmax", x = 6),
+ Inc = list(fun = "Inc", p = 100000)
+)
+```
+
+Now we are almost ready to compute the descriptors. The last detail we need to consider is the epidemiological week we want to use to compute the yearly descriptors. For many diseases such as dengue in Brasil, the start of the season does not coincide with the 1st of January but much later in the year, so it makes much more sense to use this time point. We can specify the starting epidemiological week with the argument `sweek`. In our example we set it to week 41, meaning that we will compute yearly descriptors for year `t` starting from week 41 of year `t` until week 40 of year `t+1`.
+
+Now we are ready to finally compute our descriptors with a call to `desc_year`:
+
+```{r}
+res <- desc_year(
+ data = dengue, # Input data frame
+ cases = "cases", # Name of the column of the cases
+ time = "yearweek", # Name of the column with the epiyearweek
+ space = "muni_code", # Name of the column with the spatial ID
+ pop = "pop", # Column with population, needed because of 'Inc'
+ sweek = 41, # Starting epiweek, 41 for the season of dengue in Brasil
+ descriptors = descriptors # Descriptor list
+)
+```
+
+Our descriptors have been computed! Let's have a look at the results of epidemiological year 2020 (from W41-2020 to W40-2021):
+
+```{r}
+head(res[res$epiyear == 2020, ])
+```
+
+Note that for epiyears where not all weeks are available or there are missing cases, the result will be NA, e.g.:
+
+```{r}
+head(res[res$epiyear == 2022, ])
+```
\ No newline at end of file
diff --git a/.Rproj.user/C3EAF566/sources/session-9f14958a/9810B6BD-contents b/.Rproj.user/C3EAF566/sources/session-9f14958a/9810B6BD-contents
new file mode 100644
index 0000000..891c2e1
--- /dev/null
+++ b/.Rproj.user/C3EAF566/sources/session-9f14958a/9810B6BD-contents
@@ -0,0 +1,115 @@
+#' Row bind a data frame inserting NAs if the column isn't present
+#'
+#' @param ... data.frames to be bound
+#'
+#' @returns A bound data.frame
+#' @noRd
+.rbind_fill_base <- function(...) {
+ dfs <- list(...)
+ cols <- unique(unlist(lapply(dfs, names)))
+ dfs <- lapply(dfs, function(df) {
+ missing <- setdiff(cols, names(df))
+ df[missing] <- NA
+ df[cols]
+ })
+
+ do.call(rbind, dfs)
+}
+
+
+.descriptors_list <- .rbind_fill_base(
+ # Peak indicators
+ data.frame(fun = "Ap", class = "Peak", description = "Maximum cases peak - amplitude"),
+ data.frame(
+ fun = "Tp",
+ class = "Peak",
+ description = "Week where the maximum peak occurred - time"
+ ),
+
+ # Period with cases
+ data.frame(
+ fun = "Cnf",
+ class = "Period with cases",
+ description = paste0(
+ "Frequency of periods of consecutive 'n' weeks ",
+ "or longer with at least 'x' cases"
+ ),
+ param1 = "n",
+ param2 = "x"
+ ),
+ data.frame(
+ fun = "Cmax",
+ class = "Period with cases",
+ description = "Maximum duration in consecutive weeks with at least 'x' cases",
+ param1 = "x"
+ ),
+ data.frame(
+ fun = "Cmed",
+ class = "Period with cases",
+ description = "Median duration in consecutive weeks with at least 'x' cases",
+ param1 = "x"
+ ),
+ data.frame(
+ fun = "Isof",
+ class = "Period with cases",
+ description = "Number of weeks with isolated cases"
+ ),
+ data.frame(
+ fun = "p",
+ class = "Period with cases",
+ description = "Proportion of weeks with at least 'x' cases",
+ param1 = "x"
+ ),
+
+ # Period without cases
+ data.frame(
+ fun = "Cwf",
+ class = "Period without cases",
+ description = paste0(
+ "Frequency of periods of consecutive weeks with ",
+ "at least 'n' weeks without cases."
+ ),
+ param1 = "n"
+ ),
+ data.frame(
+ fun = "Cwmax",
+ class = "Period without cases",
+ description = "Maximum duration in consecutive weeks without cases"
+ ),
+ data.frame(
+ fun = "Cwmed",
+ class = "Period without cases",
+ description = "Median duration in consecutive weeks without cases"
+ ),
+
+ # Incidence
+ data.frame(
+ fun = "Inc",
+ class = "Incidence",
+ description = "Annual incidence rate per 'p' population",
+ param1 = "p"
+ )
+)
+
+
+#' List of epidescriptors and their parameters
+#'
+#' @returns A data.frame with the funes, descriptions, classes and parameters
+#' of the descriptors included in the package.
+#' @export
+#'
+#' @examples
+#' desc_list()
+desc_list <- function() {
+ descriptors <- .descriptors_list
+ descriptors <- descriptors[c(
+ "class",
+ "fun",
+ "description",
+ "param1",
+ "param2"
+ )]
+ descriptors[is.na(descriptors)] <- ""
+
+ return(descriptors)
+}
diff --git a/.Rproj.user/C3EAF566/sources/session-9f14958a/BF74A40D-contents b/.Rproj.user/C3EAF566/sources/session-9f14958a/BF74A40D-contents
new file mode 100644
index 0000000..29df532
--- /dev/null
+++ b/.Rproj.user/C3EAF566/sources/session-9f14958a/BF74A40D-contents
@@ -0,0 +1,29 @@
+#' Ap
+#'
+#' @description Week where the maximum peak occurred.
+#'
+#' @param df A data.frame consisting of 52 rows (1 year) for a single spatial
+#' unit with columns 'time' (epiyearweek), 'cases', 'epiweek' and 'epiyear'.
+#'
+#' @returns The computed Ap epidescriptor.
+#' @export
+desc_Ap <- function(df) {
+ res <- max(df$cases)
+
+ return(res)
+}
+
+#' Tp
+#'
+#' @description Week where the maximum peak occurred.
+#'
+#' @param df A data.frame consisting of 52 rows (1 year) for a single spatial
+#' unit with columns 'time' (epiyearweek), 'cases', 'epiweek' and 'epiyear'.
+#'
+#' @returns The computed Tp epidescriptor.
+#' @export
+desc_Tp <- function(df) {
+ res <- df$epiweek[which.max(df$cases)]
+
+ return(res)
+}
diff --git a/.Rproj.user/C3EAF566/sources/session-9f14958a/CEC4EBD5-contents b/.Rproj.user/C3EAF566/sources/session-9f14958a/CEC4EBD5-contents
new file mode 100644
index 0000000..7a7a637
--- /dev/null
+++ b/.Rproj.user/C3EAF566/sources/session-9f14958a/CEC4EBD5-contents
@@ -0,0 +1,117 @@
+---
+title: "Introduction to epidesc"
+output:
+ rmarkdown::html_vignette:
+ toc: true
+vignette: >
+ %\VignetteIndexEntry{Introduction to epidesc}
+ %\VignetteEngine{knitr::rmarkdown}
+ %\VignetteEncoding{UTF-8}
+---
+
+```{r, include = FALSE}
+knitr::opts_chunk$set(
+ collapse = TRUE,
+ comment = "#>"
+)
+```
+
+# Overview
+
+The R package `epidesc` provides the tools to easily compute a series of epidemiological indicators to characterise different transmission profiles of infectious diseases. The work is based on the publication [How heterogeneous is the dengue transmission profile in Brazil? A study in six Brazilian states](https://doi.org/10.1371/journal.pntd.0010746) published in PLOS neglected tropical diseases by Iasmim Ferreira de Almeida, Raquel Martins Lana and Cláudia Torres Codeço in 2022.
+
+While we include all the indicators contained in the original publication, `epidesc` aims to expand this list of indicators, welcoming contributions from researchers (please open an issue and we'll discuss!).
+
+# Usage
+
+To show the functionality of the package, we load weekly dengue data for municipalities in Rio de Janeiro.
+
+```{r setup}
+library(epidesc)
+library(knitr)
+
+head(dengueRio)
+```
+
+## Data requirements
+
+`epidesc` has a few simple data requirements:
+
+1. The input data has to be a data.frame with the cases and spatiotemporal identifiers. In our sample data, these would be the columns *casos* (dengue cases), *date* (temporal identifier), and *regional_geocode* (spatial identifier).
+2. The data needs to be weekly with dates in `Date` format.
+3. The time series needs to be regular, i.e. 7 days between consecutive observations.
+4. If an incidence descriptor is required, the population at risk also needs to be provided.
+
+Don't worry though, if any of these aren't met, the package function will throw error messages to let you know what's happening!
+
+## Formatting dates
+
+The only required pre-processing step is to convert the dates into epidemiological yearweek format: yyyyww. We can easily do so by using the function `epiyearweek` as follows.
+
+Note that `epiyearweek` lets you choose whether epidemiological weeks start on a Sunday or a Monday via the `start` argument. If none is provided, the default is Sunday. Brazilian epidemiological weeks start on a Sunday, so this is the setting we'll use here.
+
+```{r}
+dengueRio$yearweek <- epiyearweek(dengueRio$date, start = "Sunday")
+head(dengueRio)
+```
+
+## Descriptor list
+
+To see the list of available descriptors and their required parameters, we can use the function `desc_list()`:
+
+```{r, eval = FALSE}
+desc_list()
+```
+
+```{r, echo=FALSE}
+kable(desc_list())
+```
+
+In this table we can see each indicator's class, function name, description, and required parameters. We will need this is information when we specify which descriptors we want to compute.
+
+## Computing descriptors
+
+The first step in computing the descriptors is to decide which ones to compute and what values to use for the parameters. In our case, we are interested in computing the following indicators:
+
+* *Ap*: Maximum cases peak
+* *Cmax* with `x` equal to 3 and 6: Maximum duration in consecutive weeks with at least '3' or '6' cases
+* *Inc* for 100,000 persons: Annual incidence per '100,000' persons
+
+To compute these indicators, we need to pass a nested list to the `desc_year` function. In the first level, we state the output names of the descriptors that we want to use, and in the second level, we specify the name of the function `fun` as in the table above as well as the parameters (`x`, `n` or `p` depending on the descriptor):
+
+```{r}
+descriptors <- list(
+ Ap = list(fun = "Ap"),
+ Cmax3 = list(fun = "Cmax", x = 3),
+ Cmax6 = list(fun = "Cmax", x = 6),
+ Inc = list(fun = "Inc", p = 100000)
+)
+```
+
+Now we are almost ready to compute the descriptors. The last detail we need to consider is the epidemiological week we want to use as the start of the year for computing yearly descriptors. For many diseases, such as dengue in Brazil, the start of the season does not coincide with the 1st of January but rather it occurs much later in the year, so it makes more sense to use this time point. We can specify the first epidemiological week with the argument `sweek`. In our example, we set it to week 41, meaning that yearly descriptors for year `t` will be computed starting from week 41 of year `t` until week 40 of year `t+1`.
+
+Now we are ready to finally compute our descriptors with a call to `desc_year`:
+
+```{r}
+res <- desc_year(
+ data = dengueRio, # Input data frame
+ cases = "cases", # Name of the column of the cases
+ time = "yearweek", # Name of the column with the epiyearweek
+ space = "muni_code", # Name of the column with the spatial ID
+ pop = "pop", # Column with population, needed because of 'Inc'
+ sweek = 41, # Starting epiweek, 41 for the dengue season in Brazil
+ descriptors = descriptors # Descriptor list
+)
+```
+
+Our descriptors have been computed! Let's have a look at the results of epidemiological year 2020 (from W41-2020 to W40-2021):
+
+```{r}
+head(res[res$epiyear == 2020, ])
+```
+
+Note that for epiyears where not all weeks are available or there are missing cases, the result will be NA, e.g.:
+
+```{r}
+head(res[res$epiyear == 2022, ])
+```
\ No newline at end of file
diff --git a/.Rproj.user/C3EAF566/sources/session-9f14958a/DCB84D99-contents b/.Rproj.user/C3EAF566/sources/session-9f14958a/DCB84D99-contents
new file mode 100644
index 0000000..2cf4a19
--- /dev/null
+++ b/.Rproj.user/C3EAF566/sources/session-9f14958a/DCB84D99-contents
@@ -0,0 +1,12 @@
+# This file is part of the standard setup for testthat.
+# It is recommended that you do not modify it.
+#
+# Where should you do additional test configuration?
+# Learn more about the roles of various files in:
+# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
+# * https://testthat.r-lib.org/articles/special-files.html
+
+library(testthat)
+library(epidesc)
+
+test_check("epidesc")
diff --git a/.Rproj.user/C3EAF566/sources/session-9f14958a/DCF2942E b/.Rproj.user/C3EAF566/sources/session-9f14958a/DCF2942E
new file mode 100644
index 0000000..b12993c
--- /dev/null
+++ b/.Rproj.user/C3EAF566/sources/session-9f14958a/DCF2942E
@@ -0,0 +1,24 @@
+{
+ "id": "DCF2942E",
+ "path": "~/Documents/BSC/Fundings/MSCA/Development/Analysis/epidesc/NEWS.md",
+ "project_path": "NEWS.md",
+ "type": "markdown",
+ "hash": "0",
+ "contents": "",
+ "dirty": false,
+ "created": 1784745316532.0,
+ "source_on_save": false,
+ "relative_order": 1,
+ "properties": {
+ "source_window_id": "",
+ "Source": "Source"
+ },
+ "folds": "",
+ "lastKnownWriteTime": 1784745301,
+ "encoding": "UTF-8",
+ "collab_server": "",
+ "source_window": "",
+ "last_content_update": 1784745301,
+ "read_only": false,
+ "read_only_alternatives": []
+}
\ No newline at end of file
diff --git a/.Rproj.user/C3EAF566/sources/session-9f14958a/DCF2942E-contents b/.Rproj.user/C3EAF566/sources/session-9f14958a/DCF2942E-contents
new file mode 100644
index 0000000..8962da6
--- /dev/null
+++ b/.Rproj.user/C3EAF566/sources/session-9f14958a/DCF2942E-contents
@@ -0,0 +1,3 @@
+# epidesc 0.1.0
+
+* Initial CRAN submission.
diff --git a/.Rproj.user/C3EAF566/sources/session-9f14958a/E501E439-contents b/.Rproj.user/C3EAF566/sources/session-9f14958a/E501E439-contents
new file mode 100644
index 0000000..d39089f
--- /dev/null
+++ b/.Rproj.user/C3EAF566/sources/session-9f14958a/E501E439-contents
@@ -0,0 +1,336 @@
+GNU General Public License
+==========================
+
+_Version 2, June 1991_
+_Copyright © 1989, 1991 Free Software Foundation, Inc.,_
+_51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA_
+
+Everyone is permitted to copy and distribute verbatim copies
+of this license document, but changing it is not allowed.
+
+### Preamble
+
+The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it (some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead). You can apply it to
+your programs, too.
+
+When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+We protect your rights with two steps: **(1)** copyright the software, and
+**(2)** offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+The precise terms and conditions for copying, distribution and
+modification follow.
+
+### TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+**0.** This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The “Program”, below,
+refers to any such program or work, and a “work based on the Program”
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term “modification”.) Each licensee is addressed as “you”.
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+**1.** You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+**2.** You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+* **a)** You must cause the modified files to carry prominent notices
+stating that you changed the files and the date of any change.
+* **b)** You must cause any work that you distribute or publish, that in
+whole or in part contains or is derived from the Program or any
+part thereof, to be licensed as a whole at no charge to all third
+parties under the terms of this License.
+* **c)** If the modified program normally reads commands interactively
+when run, you must cause it, when started running for such
+interactive use in the most ordinary way, to print or display an
+announcement including an appropriate copyright notice and a
+notice that there is no warranty (or else, saying that you provide
+a warranty) and that users may redistribute the program under
+these conditions, and telling the user how to view a copy of this
+License. (Exception: if the Program itself is interactive but
+does not normally print such an announcement, your work based on
+the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+**3.** You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+* **a)** Accompany it with the complete corresponding machine-readable
+source code, which must be distributed under the terms of Sections
+1 and 2 above on a medium customarily used for software interchange; or,
+* **b)** Accompany it with a written offer, valid for at least three
+years, to give any third party, for a charge no more than your
+cost of physically performing source distribution, a complete
+machine-readable copy of the corresponding source code, to be
+distributed under the terms of Sections 1 and 2 above on a medium
+customarily used for software interchange; or,
+* **c)** Accompany it with the information you received as to the offer
+to distribute corresponding source code. (This alternative is
+allowed only for noncommercial distribution and only if you
+received the program in object code or executable form with such
+an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+**4.** You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+**5.** You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+**6.** Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+**7.** If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+**8.** If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+**9.** The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and “any
+later version”, you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+**10.** If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+### NO WARRANTY
+
+**11.** BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+**12.** IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+END OF TERMS AND CONDITIONS
+
+### How to Apply These Terms to Your New Programs
+
+If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the “copyright” line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w` and `show c` should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w` and `show c`; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a “copyright disclaimer” for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ , 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.
diff --git a/.Rproj.user/C3EAF566/sources/session-9f14958a/lock_file b/.Rproj.user/C3EAF566/sources/session-9f14958a/lock_file
new file mode 100644
index 0000000..e69de29
diff --git a/.Rproj.user/shared/notebooks/patch-chunk-names b/.Rproj.user/shared/notebooks/patch-chunk-names
new file mode 100644
index 0000000..e69de29
diff --git a/.Rproj.user/shared/notebooks/paths b/.Rproj.user/shared/notebooks/paths
new file mode 100644
index 0000000..5bf8882
--- /dev/null
+++ b/.Rproj.user/shared/notebooks/paths
@@ -0,0 +1,13 @@
+/Users/diego/Documents/SINAN_SIMPLES/TODAS/final/diego_epidesc/.github/workflows/R-CMD-check.yaml="0A0998A3"
+/Users/diego/Documents/SINAN_SIMPLES/TODAS/final/diego_epidesc/LICENSE.md="2D1B9F5F"
+/Users/diego/Documents/SINAN_SIMPLES/TODAS/final/diego_epidesc/R/dengueRio.R="2A681065"
+/Users/diego/Documents/SINAN_SIMPLES/TODAS/final/diego_epidesc/R/desc-cases.R="DCF6B33D"
+/Users/diego/Documents/SINAN_SIMPLES/TODAS/final/diego_epidesc/R/desc-inc.R="CFEA1EBC"
+/Users/diego/Documents/SINAN_SIMPLES/TODAS/final/diego_epidesc/R/desc-peak.R="35454B90"
+/Users/diego/Documents/SINAN_SIMPLES/TODAS/final/diego_epidesc/R/desc_list.R="ECCAA99E"
+/Users/diego/Documents/SINAN_SIMPLES/TODAS/final/diego_epidesc/R/desc_year.R="8E090E43"
+/Users/diego/Documents/SINAN_SIMPLES/TODAS/final/diego_epidesc/R/epidesc-package.R="485E53C2"
+/Users/diego/Documents/SINAN_SIMPLES/TODAS/final/diego_epidesc/README.md="561F8696"
+/Users/diego/Documents/SINAN_SIMPLES/TODAS/final/diego_epidesc/RELATORIO_MUDANCAS.md="5F51372E"
+/Users/diego/Documents/SINAN_SIMPLES/TODAS/final/diego_epidesc/tests/testthat.R="CA25057F"
+/Users/diego/Documents/SINAN_SIMPLES/TODAS/final/diego_epidesc/vignettes/epidesc.Rmd="1F10D5B9"
diff --git a/NEWS.md b/NEWS.md
index 8962da6..11fff39 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,3 +1,10 @@
# epidesc 0.1.0
-* Initial CRAN submission.
+* Initial release.
+* Provides `epiyearweek()` to format dates in epiyearweek (`"yyyyww"`) format.
+* Provides the epidemiological descriptors `desc_Ap()`, `desc_Tp()`,
+ `desc_Cnf()`, `desc_Cmax()`, `desc_Cmed()`, `desc_Isof()`, `desc_p()`,
+ `desc_Cwf()`, `desc_Cwmax()`, `desc_Cwmed()` and `desc_Inc()`.
+* Provides `desc_list()` with the catalogue of available descriptors and
+ `desc_year()` to compute them per spatial unit and epidemiological year.
+* Includes the `dengueRio` example dataset.
diff --git a/R/desc_year.R b/R/desc_year.R
index 1ab6942..8206cf7 100644
--- a/R/desc_year.R
+++ b/R/desc_year.R
@@ -148,7 +148,7 @@ desc_year <- function(
if (!all(rangeepi %in% uniquetimes)) {
stop(
"The time series is not regular, missing times ",
- paste(rangeepi[!rangeepi %in% uniquetimes], collapse = "")
+ paste(rangeepi[!rangeepi %in% uniquetimes], collapse = " ")
)
}
}
@@ -157,8 +157,8 @@ desc_year <- function(
desc_names <- sapply(descriptors, `[[`, "fun")
if (!all(desc_names %in% .descriptors_list$fun)) {
stop(
- "Unkown descriptors: ",
- paste(desc_names[!desc_names %in% .descriptors_list$fun], collapse = "")
+ "Unknown descriptors: ",
+ paste(desc_names[!desc_names %in% .descriptors_list$fun], collapse = " ")
)
}
@@ -300,12 +300,32 @@ desc_year <- function(
# 2. Descriptors ----
# Split by space and epiyear
- datasplit <- split(dataclean, ~ space + epiyear)
+ datasplit <- split(dataclean, ~ space + epiyear, drop = TRUE)
- # Compute descriptors
- res <- lapply(datasplit, .compute_descriptors, descriptors = descriptors)
- res <- as.data.frame(do.call(rbind, res))
- rownames(res) <- NULL
+ # Resolve descriptor functions and their arguments once
+ desc_funs <- lapply(descriptors, function(desc) {
+ list(
+ fun = match.fun(paste0("desc_", desc$fun)),
+ args = desc[names(desc) != "fun"]
+ )
+ })
+
+ # Compute descriptors: a numeric matrix (groups x descriptors)
+ valmat <- do.call(
+ rbind,
+ lapply(datasplit, .compute_descriptors, desc_funs = desc_funs)
+ )
+ colnames(valmat) <- names(descriptors)
+
+ # Recover the spatial and temporal identifiers of each group (preserving type)
+ res <- data.frame(
+ space = unlist(lapply(datasplit, function(df) df$space[1]), use.names = FALSE),
+ epiyear = unlist(lapply(datasplit, function(df) df$epiyear[1]), use.names = FALSE),
+ valmat,
+ row.names = NULL,
+ check.names = FALSE,
+ stringsAsFactors = FALSE
+ )
names(res)[1] <- space # Recover name of the space column
# 3. Return ----
@@ -317,31 +337,21 @@ desc_year <- function(
#' @param df A data.frame consisting of 52 rows (1 year) for
#' a single spatial unit with columns 'time' (epiyearweek), 'space', 'cases',
#' 'epiweek' and 'epiyear'.
-#' @param descriptors A list indicating the epidescriptors to compute and their
-#' parameters. See [desc_year].
+#' @param desc_funs A list of pre-resolved descriptors, each element a list with
+#' the resolved function `fun` and its arguments `args`. See [desc_year].
#'
-#' @returns A data.frame with the computed descriptors
+#' @returns A named numeric vector with the computed descriptors.
#' @noRd
-.compute_descriptors <- function(df, descriptors) {
+.compute_descriptors <- function(df, desc_funs) {
# The year is not complete or there are NAs
if (!nrow(df) %in% c(52, 53) || anyNA(df[["cases"]])) {
- res <- as.data.frame(matrix(NA, nrow = 1, ncol = length(descriptors)))
- names(res) <- names(descriptors)
- } else {
- # Compute descriptors
- res <- lapply(descriptors, function(desc) {
- fun <- desc$fun
- fun <- match.fun(paste0("desc_", fun))
- args <- desc[names(desc) != "fun"]
- do.call(fun, c(list(df), args))
- })
- res <- as.data.frame(as.list(res))
- names(res) <- names(descriptors)
+ return(rep(NA_real_, length(desc_funs)))
}
- # Add temporal and spatial IDs
- IDs <- data.frame(space = df$space[1], epiyear = df$epiyear[1])
- res <- cbind(IDs, res)
-
- res
+ # Compute descriptors
+ vapply(
+ desc_funs,
+ function(desc) do.call(desc$fun, c(list(df), desc$args)),
+ numeric(1)
+ )
}
diff --git a/RELATORIO_MUDANCAS.md b/RELATORIO_MUDANCAS.md
new file mode 100644
index 0000000..705bd3f
--- /dev/null
+++ b/RELATORIO_MUDANCAS.md
@@ -0,0 +1,58 @@
+# epidesc — Relatório de mudanças (CRAN)
+
+Data: 2026-07-23 · Base: branch `main` \<- `Diego`
+
+Validação após as mudanças
+
+- `R CMD check` (via `devtools::check`): **0 errors \| 0 warnings \| 0 notes** (Status: OK)
+- Testes (`testthat`, edition 3): **67 PASS, 0 falhas**
+- `desc_year()` refatorado: saída **idêntica** à original (644×12, mesmos valores e tipos), verificado comparando com a versão de `main`.
+
+## Resumo (21 arquivos, +97 / −51)
+
+### 1. Metadados / submissão CRAN
+
+- **`DESCRIPTION`**: referência do campo `Description` passou de `(https://doi.org/10.1371/journal.pntd.0010746)` para `'How heterogeneous ...' ` (formato exigido pelo CRAN). O `devtools::document()` também trocou `RoxygenNote: 7.3.3` por `Config/roxygen2/version: 8.0.0` (roxygen2 v8).
+- **`.Rbuildignore`**: adicionadas as regras `^LICENSE\.md$`, `^cran-comments\.md$`, `^AVALIACAO_CRAN\.md$`, `^\.DS_Store$` e os padrões de `.Rproj`. Isso **elimina a única NOTE** ("Non-standard file/directory found at top level: LICENSE.md").
+- **`.gitignore`** (novo): ignora `.Rproj.user`, `.Rhistory`, `.RData`, `.Ruserdata`, `.DS_Store`.
+- **`NEWS.md`** (novo): notas da versão 0.1.0.
+- **`cran-comments.md`** (novo): comentários de submissão para o CRAN.
+
+### 2. Correções de documentação (roxygen) — `R/*.R` e `man/*.Rd`
+
+- `R/desc-peak.R` — `desc_Ap`: `@description` descrevia o `Tp` ("Week where the maximum peak occurred"); corrigido para "Maximum weekly case count (height of the epidemic peak)".
+- `R/desc-inc.R` — `desc_Inc`: `@returns` dizia "Ap epidescriptor" → "Inc".
+- `R/desc-withoutcases.R` — `desc_Cwmax`/`desc_Cwmed`: `@returns` diziam "Cmax"/"Cmed" → "Cwmax"/"Cwmed".
+- `R/epiyearweek.R` — `@returns` dizia "integer vector"; corrigido para "character vector ... `\"yyyyww\"`" (a função retorna character).
+- Typos: `R/desc-cases.R` "Proportion **fo**" → "of"; `R/desc_list.R` "the **funes**" → "functions"; `R/desc_year.R` "**Unkown**" → "Unknown".
+- Arquivos `man/*.Rd` regenerados via `devtools::document()`.
+
+### 3. Robustez de mensagens de erro — `R/desc_year.R`
+
+- Mensagens `stop()` que listam elementos agora usam `collapse = " "` (antes concatenavam sem separador), melhorando a legibilidade.
+- `split(..., drop = TRUE)` evita processar combinações espaço×ano vazias.
+
+### 4. Desempenho — `R/desc_year.R`
+
+- As funções dos descritores são resolvidas **uma única vez** (`match.fun`) antes do loop de grupos, em vez de a cada grupo/descritor.
+- O resultado é montado como **matriz numérica** (`do.call(rbind, ...)` de vetores) e convertido em data.frame ao final, em vez de milhares de data.frames de 1 linha.
+- O helper interno `.compute_descriptors()` passou a retornar um vetor numérico nomeado (antes um data.frame de 1 linha).
+- Comportamento e saída **inalterados**; ganho de tempo modesto em escala (ex.: stress 40× de `dengueRio`, \~1,15M linhas: \~71s → \~61s). O gargalo remanescente é o `split()` sobre muitos grupos e as chamadas do `nseq` por grupo — otimização adicional (ex.: `data.table`) fica como trabalho futuro.
+
+### 5. Testes — `tests/testthat/test-desc_year.R`
+
+- Ajustada a expectativa de mensagem de erro de "Unkown descriptors" para "Unknown descriptors", acompanhando a correção do typo no código.
+
+## Como aplicar no seu repositório
+
+Opção A — a partir do zip: substitua os arquivos do pacote pelos desta versão.
+
+Opção B — via patch (`epidesc_cran_readiness.patch`, enviado antes):
+
+``` sh
+cd epidesc
+git checkout -b cran-readiness
+git apply epidesc_cran_readiness.patch # ou: git am < epidesc_cran_readiness.patch
+```
+
+Depois: `devtools::document()` (opcional, já incluído) e `devtools::check()`.
diff --git a/tests/testthat/test-desc_year.R b/tests/testthat/test-desc_year.R
index 9f2f707..77b6f31 100644
--- a/tests/testthat/test-desc_year.R
+++ b/tests/testthat/test-desc_year.R
@@ -148,7 +148,7 @@ test_that("desc_year errors on unknown descriptor name", {
bad_desc <- list(X = list(fun = "NotADescriptor"))
expect_error(
desc_year(dfval, "cases", "epiyw", "spatialID", bad_desc),
- "Unkown descriptors"
+ "Unknown descriptors"
)
})
test_that("desc_year errors if required descriptor parameter is missing", {