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

Run {styler} #26

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion R/add_cols.R
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ NULL
infector_names <- data.frame(id = .data$id, infector_name = .data$case_name)
col_order <- c(colnames(.data), "infector_name")
.data <- merge(
.data, infector_names, by.x = "infector", by.y = "id", all.x = TRUE
.data, infector_names,
by.x = "infector", by.y = "id", all.x = TRUE
)
.data <- .data[order(is.na(.data$infector_name), decreasing = TRUE), ]
.data <- .data[col_order]
Expand Down
9 changes: 4 additions & 5 deletions R/checkers.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
#' invalid.
#' @keywords internal
.check_age_df <- function(x) {

# check input
stopifnot(
"column names should be 'age_range' & 'proportion'" =
Expand Down Expand Up @@ -140,7 +139,7 @@
stopifnot(
"population_age must be two numerics or a data.frame" =
is.numeric(population_age) && length(population_age) == 2 ||
is.data.frame(population_age)
is.data.frame(population_age)
)

if (sim_type == "linelist" || sim_type == "outbreak") {
Expand All @@ -159,13 +158,13 @@
sum(case_type_probs) == 1,
"hosp_rate must be a single numeric or a data.frame" =
is.numeric(hosp_rate) && length(hosp_rate) == 1 ||
is.data.frame(hosp_rate),
is.data.frame(hosp_rate),
"hosp_death_rate must be a single numeric or a data.frame" =
is.numeric(hosp_death_rate) && length(hosp_death_rate) == 1 ||
is.data.frame(hosp_death_rate),
is.data.frame(hosp_death_rate),
"non_hosp_death_rate must be a single numeric or a data.frame" =
is.numeric(non_hosp_death_rate) && length(non_hosp_death_rate) == 1 ||
is.data.frame(non_hosp_death_rate)
is.data.frame(non_hosp_death_rate)
)
}

Expand Down
1 change: 0 additions & 1 deletion R/create_linelist.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
#' @return A `<data.frame>`.
#' @keywords internal
.create_linelist <- function(scenario) {

scenario <- match.arg(
arg = scenario,
choices = c(
Expand Down
1 change: 0 additions & 1 deletion R/dev-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ release_bullets <- function() { # nocov start
"Run `goodpractice::gp()`",
"Review [WORDLIST](https://docs.cran.dev/spelling#wordlist)"
)

} # nocov end
1 change: 0 additions & 1 deletion R/sim_contacts.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ sim_contacts <- function(R,
),
config = create_config(),
...) {

chkDots(...)

.check_sim_input(
Expand Down
8 changes: 4 additions & 4 deletions R/sim_contacts_tbl.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
population_age,
contact_tracing_status_probs,
config) {

if (!"infector_name" %in% colnames(.data)) {
.data <- .add_names(.data = .data)
}
Expand All @@ -20,7 +19,8 @@
.data,
select = c(
"infector", "infector_name", "case_name", "age", "gender",
"date_first_contact", "date_last_contact")
"date_first_contact", "date_last_contact"
)
)
colnames(contact_investigation) <- c(
"infector", "from", "to", "cnt_age", "cnt_gender",
Expand All @@ -43,7 +43,7 @@
nrow(other_contacts)
)

#Multiply row by times specified in frequency column V
# Multiply row by times specified in frequency column V
other_contacts <-
other_contacts[rep(row.names(other_contacts), contact_freq), ]

Expand Down Expand Up @@ -73,7 +73,7 @@
replace = TRUE
)

#Add corresponding names acc to the gender V
# Add corresponding names acc to the gender V
other_contacts$to <- randomNames::randomNames(
which.names = "both",
name.sep = " ",
Expand Down
1 change: 0 additions & 1 deletion R/sim_linelist.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ sim_linelist <- function(R,
),
config = create_config(),
...) {

chkDots(...)

.check_sim_input(
Expand Down
8 changes: 4 additions & 4 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ If both the line list and contacts table are required, they can be jointly simul

```{r, sim-outbreak}
outbreak <- sim_outbreak(
R = 1.1,
serial_interval = serial_interval,
onset_to_hosp = onset_to_hosp,
onset_to_death = onset_to_death,
R = 1.1,
serial_interval = serial_interval,
onset_to_hosp = onset_to_hosp,
onset_to_death = onset_to_death,
contact_distribution = contact_distribution
)
head(outbreak$linelist)
Expand Down
152 changes: 77 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,20 @@ linelist <- sim_linelist(
onset_to_death = onset_to_death
)
head(linelist)
#> id case_name case_type gender age onset_date
#> 1 1 Wajdi al-Matar probable m 69 2023-01-01
#> 2 2 Brandon Meeks confirmed m 14 2023-01-01
#> 3 3 Darrien Fernandez confirmed m 72 2023-01-02
#> 4 4 Jalond Ramos probable m 66 2023-01-02
#> 5 5 Rudy Sanchez Vergara probable m 24 2023-01-03
#> 6 6 Abdul Jabbaar al-Koroma suspected m 86 2023-01-02
#> hospitalisation_date date_first_contact date_last_contact
#> 1 <NA> <NA> <NA>
#> 2 2023-01-08 2022-12-28 2023-01-02
#> 3 <NA> 2023-01-01 2023-01-04
#> 4 2023-01-04 2023-01-01 2023-01-05
#> 5 <NA> 2022-12-29 2023-01-04
#> 6 2023-01-04 2022-12-31 2023-01-04
#> id case_name case_type gender age date_onset date_admission
#> 1 1 Aliyah Bunck suspected f 84 2023-01-01 2023-01-03
#> 2 2 Rayel Roman confirmed f 62 2023-01-01 <NA>
#> 3 3 Alex Fuentes suspected m 53 2023-01-01 2023-01-02
#> 4 4 Nusaiba al-Wahab confirmed f 6 2023-01-02 <NA>
#> 5 5 Monica Alvarez Valentin probable f 86 2023-01-02 <NA>
#> 6 6 Adelaide Weible confirmed f 39 2023-01-02 <NA>
#> date_death date_first_contact date_last_contact
#> 1 <NA> <NA> <NA>
#> 2 <NA> 2022-12-30 2023-01-04
#> 3 2023-01-26 2023-01-01 2023-01-04
#> 4 <NA> 2023-01-01 2023-01-05
#> 5 2023-01-19 2023-01-03 2023-01-04
#> 6 <NA> 2023-01-05 2023-01-07
```

In this example, the line list is simulated using the default values
Expand All @@ -134,20 +134,20 @@ linelist <- sim_linelist(
outbreak_start_date = as.Date("2019-12-01")
)
head(linelist)
#> id case_name case_type gender age onset_date
#> 1 1 Ghaazi al-Shad probable m 5 2019-12-01
#> 2 2 Uriel Vigil confirmed m 38 2019-12-01
#> 3 3 Azhaar al-Mussa suspected m 21 2019-12-02
#> 4 4 Kabeer el-Khatib suspected m 22 2019-12-01
#> 5 5 Dhipthika Rezaie-Khodabandelou probable f 52 2019-12-02
#> 6 6 Kalyn Lovejoy suspected f 67 2019-12-03
#> hospitalisation_date date_first_contact date_last_contact
#> 1 <NA> <NA> <NA>
#> 2 <NA> 2019-11-29 2019-12-04
#> 3 <NA> 2019-11-26 2019-12-01
#> 4 <NA> 2019-11-28 2019-12-01
#> 5 <NA> 2019-11-30 2019-12-03
#> 6 <NA> 2019-12-03 2019-12-04
#> id case_name case_type gender age date_onset date_admission date_death
#> 1 1 Melissa Moralez confirmed f 41 2019-12-01 <NA> <NA>
#> 2 2 Lorna Gries suspected f 72 2019-12-01 <NA> <NA>
#> 3 3 Saood el-Salik suspected m 39 2019-12-01 <NA> <NA>
#> 4 4 Antonio Trujillo probable m 61 2019-12-02 <NA> <NA>
#> 5 5 Aaron Kimble confirmed m 3 2019-12-01 <NA> <NA>
#> 6 6 Gage Declaw confirmed m 6 2019-12-02 <NA> 2019-12-14
#> date_first_contact date_last_contact
#> 1 <NA> <NA>
#> 2 2019-11-28 2019-12-03
#> 3 2019-11-28 2019-12-01
#> 4 2019-12-03 2019-12-06
#> 5 2019-12-02 2019-12-03
#> 6 2019-11-30 2019-12-04
```

To simulate a table of contacts we can reuse the serial interval from
Expand All @@ -170,20 +170,20 @@ contacts <- sim_contacts(
contact_distribution = contact_distribution
)
head(contacts)
#> part_name contact_name cnt_age cnt_gender date_first_contact
#> 1 Macario Sandoval David Torres 63 m 2022-12-29
#> 2 Macario Sandoval Dong Sung Abraham 84 m 2022-12-31
#> 3 Macario Sandoval Callie Lakkaraju 59 f 2022-12-29
#> 4 Macario Sandoval Isaac Pinedo Carrillo 39 m 2022-12-31
#> 5 David Torres Aydee Luna Gonzalez 32 f 2022-12-28
#> 6 David Torres Ric Noble 74 m 2023-01-03
#> from to cnt_age cnt_gender date_first_contact
#> 1 Ryan Xiong Fawz el-Noor 89 m 2023-01-03
#> 2 Ryan Xiong Oleta Knapp 2 f 2023-01-02
#> 3 Ryan Xiong Yohana Bontrager 24 f 2022-12-31
#> 4 Ryan Xiong Danyelle Dowdell 3 f 2023-01-03
#> 5 Ryan Xiong Lorena Dominguez 66 f 2023-01-02
#> 6 Ryan Xiong Jonathan Kercher 89 m 2023-01-03
#> date_last_contact was_case status
#> 1 2023-01-03 Y case
#> 2 2023-01-02 N under_followup
#> 1 2023-01-04 Y case
#> 2 2023-01-03 Y case
#> 3 2023-01-04 N under_followup
#> 4 2023-01-04 N under_followup
#> 5 2023-01-03 Y case
#> 6 2023-01-05 N lost_to_followup
#> 4 2023-01-06 N lost_to_followup
#> 5 2023-01-05 N lost_to_followup
#> 6 2023-01-06 N under_followup
```

If both the line list and contacts table are required, they can be
Expand All @@ -194,42 +194,42 @@ the same default settings as the other functions).

``` r
outbreak <- sim_outbreak(
R = 1.1,
serial_interval = serial_interval,
onset_to_hosp = onset_to_hosp,
onset_to_death = onset_to_death,
R = 1.1,
serial_interval = serial_interval,
onset_to_hosp = onset_to_hosp,
onset_to_death = onset_to_death,
contact_distribution = contact_distribution
)
head(outbreak$linelist)
#> id case_name case_type gender age onset_date
#> 1 1 Simon Garver confirmed m 50 2023-01-01
#> 2 2 Anthony Tomas suspected m 78 2023-01-01
#> 3 3 Abdul Maalik al-Mahdavi probable m 40 2023-01-02
#> 4 4 Saabiqa al-Pour suspected f 4 2023-01-02
#> 5 5 Alexis Martin probable f 68 2023-01-02
#> 6 6 Desiree Shackelford confirmed f 82 2023-01-02
#> hospitalisation_date date_first_contact date_last_contact
#> 1 2023-01-07 <NA> <NA>
#> 2 <NA> 2023-01-06 2023-01-07
#> 3 <NA> 2023-01-01 2023-01-04
#> 4 <NA> 2022-12-28 2023-01-03
#> 5 2023-01-03 2022-12-30 2023-01-03
#> 6 <NA> 2022-12-29 2023-01-04
#> id case_name case_type gender age date_onset date_admission
#> 1 1 Albert Brown suspected m 78 2023-01-01 <NA>
#> 2 2 Martin Menning probable m 32 2023-01-01 <NA>
#> 3 3 Drayas Fenton probable m 85 2023-01-01 <NA>
#> 4 4 Michael Wilkerson suspected m 60 2023-01-02 2023-01-07
#> 5 5 Essence Fadler probable f 86 2023-01-01 <NA>
#> 6 6 Erika Trujillo confirmed f 15 2023-01-02 <NA>
#> date_death date_first_contact date_last_contact
#> 1 2023-01-23 <NA> <NA>
#> 2 2023-01-11 2022-12-31 2023-01-03
#> 3 <NA> 2023-01-02 2023-01-07
#> 4 2023-01-18 2022-12-28 2023-01-02
#> 5 2023-01-12 2023-01-05 2023-01-05
#> 6 <NA> 2023-01-02 2023-01-06
head(outbreak$contacts)
#> part_name contact_name cnt_age cnt_gender date_first_contact
#> 1 Simon Garver Anthony Tomas 78 m 2023-01-06
#> 2 Simon Garver Abdul Maalik al-Mahdavi 40 m 2023-01-01
#> 3 Simon Garver Katherine Smit 42 f 2022-12-31
#> 4 Simon Garver Judy Ragoschke 6 f 2023-01-02
#> 5 Simon Garver Zuhair al-Ishak 70 m 2023-01-01
#> 6 Simon Garver Donna Cummings 20 f 2022-12-31
#> date_last_contact was_case status
#> 1 2023-01-07 Y case
#> 2 2023-01-04 Y case
#> 3 2023-01-03 N under_followup
#> 4 2023-01-03 N under_followup
#> 5 2023-01-04 N lost_to_followup
#> 6 2023-01-04 N lost_to_followup
#> from to cnt_age cnt_gender date_first_contact
#> 1 Albert Brown Martin Menning 32 m 2022-12-31
#> 2 Albert Brown Drayas Fenton 85 m 2023-01-02
#> 3 Albert Brown Areli Vigil 6 f 2022-12-30
#> 4 Albert Brown Long Farley 25 m 2023-01-01
#> 5 Albert Brown Abigail Zagal 17 f 2023-01-03
#> 6 Martin Menning Michael Wilkerson 60 m 2022-12-28
#> date_last_contact was_case status
#> 1 2023-01-03 Y case
#> 2 2023-01-07 Y case
#> 3 2023-01-03 N under_followup
#> 4 2023-01-04 N under_followup
#> 5 2023-01-05 N under_followup
#> 6 2023-01-02 Y case
```

## Help
Expand Down Expand Up @@ -257,16 +257,18 @@ citation("simulist")
#> To cite package 'simulist' in publications use:
#>
#> Lambert J, Tamayo C (2023). _simulist: Tools to Simulated Line list
#> Data_. https://github.com/epiverse-trace/simulist,
#> https://epiverse-trace.github.io/simulist/.
#> Data_. R package version 0.0.0.9000,
#> https://epiverse-trace.github.io/simulist/,
#> <https://github.com/epiverse-trace/simulist>.
#>
#> A BibTeX entry for LaTeX users is
#>
#> @Manual{,
#> title = {simulist: Tools to Simulated Line list Data},
#> author = {Joshua W. Lambert and Carmen Tamayo},
#> year = {2023},
#> note = {https://github.com/epiverse-trace/simulist,
#> note = {R package version 0.0.0.9000,
#> https://epiverse-trace.github.io/simulist/},
#> url = {https://github.com/epiverse-trace/simulist},
#> }
```
18 changes: 12 additions & 6 deletions tests/testthat/test-create_config.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ test_that("create_config works as expected with defaults", {
expect_length(config, 6)
expect_named(
config,
c("last_contact_distribution", "last_contact_distribution_params",
c(
"last_contact_distribution", "last_contact_distribution_params",
"first_contact_distribution", "first_contact_distribution_params",
"ct_distribution", "ct_distribution_params")
"ct_distribution", "ct_distribution_params"
)
)
})

Expand All @@ -16,9 +18,11 @@ test_that("create_config works as expected modifying element", {
expect_length(config, 6)
expect_named(
config,
c("last_contact_distribution", "last_contact_distribution_params",
c(
"last_contact_distribution", "last_contact_distribution_params",
"first_contact_distribution", "first_contact_distribution_params",
"ct_distribution", "ct_distribution_params")
"ct_distribution", "ct_distribution_params"
)
)
expect_identical(config$last_contact_distribution, "geom")
})
Expand All @@ -30,9 +34,11 @@ test_that("create_config works as expected misspelling modifying element", {
expect_length(config, 6)
expect_named(
config,
c("last_contact_distribution", "last_contact_distribution_params",
c(
"last_contact_distribution", "last_contact_distribution_params",
"first_contact_distribution", "first_contact_distribution_params",
"ct_distribution", "ct_distribution_params")
"ct_distribution", "ct_distribution_params"
)
)
expect_identical(config$last_contact_distribution, "pois")
})
Loading