Birthing the pregnancy package

Ella Kaye

September 17, 2025

How it started…

how_far()
I am 15 weeks and 5 days pregnant.
All going well, I am due in 24 weeks and 2 days.
(That's 91 injections down, 170 to go...)

useful for me → useful for others

easy and personal

make the package a pleasure to use

tips and tricks

options and %||%

{rlang} and {cli}

utility and helper functions

Pregnancy 1

library(pregnancy)
how_far()
 You are 28 weeks and 0 days pregnant.
 That's 12 weeks and 0 days until the due date (December 01, 2025).
 You are 70% through the pregnancy.

Pregnancy 2

how_far()
 I am 35 weeks and 3 days pregnant.
 That's 4 weeks and 4 days until the due date (October 10, 2025).
 I am 89% through the pregnancy.

Pregnancy 3

how_far(on_date = "2025-12-25")
 On December 25, 2025, Ruth will be 36 weeks and 2 days
pregnant.
date_when(weeks = 33)
 On December 02, 2025, Ruth will be 33 weeks pregnant.
 That's 12 weeks and 1 day away.

NULL defaults

how_far(
  on_date = Sys.Date(), 
  due_date = NULL, 
  person = NULL
)

options and %||%

due_date <- due_date %||%
  getOption("pregnancy.due_date") %||%
  date_stop(due_date)

Helpful errors with {rlang} and {cli}

how_far()
`due_date` must have class <Date> or <character>.
ℹ It was NULL instead.
ℹ You can do one of the following:
• set the `due_date` argument
• set the 'pregnancy.due_date' option for this R session with
  `set_due_date(due_date)`
• (recommended) set `options(pregnancy.due_date)` in your `.Rprofile`.
ℹ See the pregnancy::pregnancy vignette for further details.

ellakaye.github.io/pregnancy

make your package a pleasure to use