Skip to content

Commit

Permalink
Merge pull request #34 from nhs-r-community/all-contributors/add-TimT…
Browse files Browse the repository at this point in the history
…aylor

docs: add TimTaylor as a contributor for doc
  • Loading branch information
Lextuga007 authored Oct 7, 2024
2 parents 5ebecda + 9b950e4 commit 11ec7e3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 32 deletions.
20 changes: 19 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
{
"projectName": "NHSRepisodes",
"projectOwner": "nhs-r-community"
"projectOwner": "nhs-r-community",
"files": [
"README.md"
],
"commitType": "docs",
"commitConvention": "angular",
"contributorsPerLine": 7,
"contributors": [
{
"login": "TimTaylor",
"name": "Tim Taylor",
"avatar_url": "https://avatars.githubusercontent.com/u/43499035?v=4",
"profile": "https://github.com/TimTaylor",
"contributions": [
"doc",
"test"
]
}
]
}
4 changes: 3 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
out.width = "100%",
cache = TRUE
)
```

Expand All @@ -28,6 +29,7 @@ knitr::opts_chunk$set(
<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![R-CMD-check](https://github.com/nhs-r-community/NHSRepisodes/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/nhs-r-community/NHSRepisodes/actions/workflows/R-CMD-check.yaml)
[![All Contributors](https://img.shields.io/github/all-contributors/nhs-r-community/NHSRepisodes?color=ee8449&style=flat-square)](#contributors)
<!-- badges: end -->

## Installation instructions
Expand Down
61 changes: 31 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![R-CMD-check](https://github.com/nhs-r-community/NHSRepisodes/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/nhs-r-community/NHSRepisodes/actions/workflows/R-CMD-check.yaml)
[![All
Contributors](https://img.shields.io/github/all-contributors/nhs-r-community/NHSRepisodes?color=ee8449&style=flat-square)](#contributors)
<!-- badges: end -->

## Installation instructions
Expand Down Expand Up @@ -57,7 +59,7 @@ mutate(tibble(packages), version = sapply(packages, getNamespaceVersion))
#> packages version
#> <chr> <chr>
#> 1 NHSRepisodes 0.1.0.9000
#> 2 dplyr 1.1.4.9000
#> 2 dplyr 1.1.4
#> 3 data.table 1.16.0
#> 4 ivs 0.2.0

Expand Down Expand Up @@ -126,18 +128,18 @@ end2 <- start2 + sample(1:100, size = n * 5, replace = TRUE)
# creates the object big_dat and shows the first 10 rows as a tibble in the console
(big_dat <- tibble(id = id2, start = start2, end = end2))
#> # A tibble: 625,000 × 3
#> id start end
#> <int> <date> <date>
#> 1 90983 2020-02-07 2020-03-18
#> 2 59640 2020-07-05 2020-08-13
#> 3 29543 2020-04-05 2020-05-28
#> 4 17962 2020-06-07 2020-07-21
#> 5 13032 2020-08-25 2020-09-08
#> 6 94348 2020-05-11 2020-06-07
#> 7 7770 2020-03-18 2020-04-03
#> 8 9570 2020-09-25 2020-12-04
#> 9 86687 2020-11-04 2021-01-09
#> 10 66213 2020-04-09 2020-04-16
#> id start end
#> <int> <date> <date>
#> 1 47215 2020-12-29 2021-02-16
#> 2 91739 2020-09-16 2020-11-12
#> 3 114791 2020-01-31 2020-02-27
#> 4 83644 2020-08-17 2020-11-04
#> 5 68824 2020-02-14 2020-05-06
#> 6 100194 2020-12-11 2021-03-18
#> 7 3871 2020-06-21 2020-07-06
#> 8 118901 2020-01-09 2020-03-23
#> 9 80676 2020-07-23 2020-08-19
#> 10 84580 2020-07-17 2020-10-07
#> # ℹ 624,990 more rows

# checking the time to run
Expand All @@ -148,7 +150,7 @@ system.time(
reframe(interval = iv_groups(interval, abutting = FALSE), .by = id)
)
#> user system elapsed
#> 13.870 0.065 13.996
#> 17.00 0.28 17.30
```

If you were not already using it, this is likely the time you would
Expand All @@ -175,32 +177,32 @@ fun <- function(s, e) {

system.time(out_dt <- DT[, fun(start, end + 1), by = id])
#> user system elapsed
#> 14.972 0.022 14.984
#> 19.26 0.49 19.77
```

***NHSRepisodes*** solves this with the `merge_episodes()` function:

``` r
merge_episodes(big_dat)
#> # A tibble: 334,767 × 4
#> # A tibble: 335,828 × 4
#> id .interval_number .episode_start .episode_end
#> <int> <int> <date> <date>
#> 1 1 1 2020-04-16 2020-06-23
#> 2 2 1 2020-01-12 2020-02-22
#> 3 2 2 2020-07-22 2020-08-16
#> 4 2 3 2020-09-27 2021-01-11
#> 5 3 1 2020-01-06 2020-03-02
#> 6 3 2 2020-03-08 2020-03-16
#> 7 3 3 2020-06-05 2020-08-26
#> 8 4 1 2020-02-05 2020-05-03
#> 9 4 2 2020-05-19 2020-09-08
#> 10 5 1 2020-01-14 2020-03-13
#> # ℹ 334,757 more rows
#> 1 1 1 2020-01-15 2020-01-27
#> 2 1 2 2020-02-13 2020-11-14
#> 3 1 3 2020-11-15 2021-02-13
#> 4 2 1 2020-01-03 2020-03-25
#> 5 2 2 2020-03-31 2020-06-09
#> 6 2 3 2020-10-31 2020-11-08
#> 7 2 4 2020-12-17 2021-01-23
#> 8 3 1 2020-03-08 2020-03-19
#> 9 3 2 2020-04-13 2020-05-26
#> 10 3 3 2020-11-30 2020-12-01
#> # ℹ 335,818 more rows

# And for comparison with earlier timings
system.time(out <- merge_episodes(big_dat))
#> user system elapsed
#> 0.917 0.000 0.335
#> 0.59 0.11 0.44

# equal output (subject to ordering)
out <- out |>
Expand Down Expand Up @@ -240,13 +242,12 @@ add_parent_interval(dat)
#> 7 1 2020-01-01 2020-01-10 2020-01-01 2020-01-10 1
#> 8 1 2020-01-11 2020-01-12 2020-01-11 2020-01-12 2
```

## Contributors

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

0 comments on commit 11ec7e3

Please sign in to comment.