how_far: Calculate pregnancy progress and time remaining

View source: R/how_far.R

how_farR Documentation

Calculate pregnancy progress and time remaining

Description

Calculates and displays how far along a pregnancy is on a specific date, including weeks pregnant, days remaining until due date, and overall progress percentage.

Usage

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

Arguments

on_date

Date or character string representing a date, e.g. "YYYY-MM-DD". The date for which to calculate pregnancy progress. Defaults to current system date.

due_date

Date or character string representing a date, e.g. "YYYY-MM-DD". The expected due date. If NULL, will try to use the "pregnancy.due_date" option. Required if option not set.

person

The person who is pregnant, to determine the grammar for the output message. Can be:

  • "I", "1", "1st", "first", or numeric 1 for first person

  • "you", "2", "2nd", "second", or numeric 2 for second person

  • Any other name for third person

  • NULL: will try to use the "pregnancy.person" option. Defaults to "You" if the option is set.

Details

The function assumes a standard pregnancy length of 280 days (40 weeks) when calculating progress. It handles past, present, and future dates appropriately by adjusting message grammar. If the calculation shows more than 42 weeks of pregnancy, a different message is displayed noting this unusual duration.

The function uses the cli package for formatted message output and supports proper pluralization of weeks/days in messages.

If on_date or due_date are character strings, the conversion to a Date is handled by anytime::anydate().

Value

Invisibly returns the number of days along in the pregnancy. Prints a formatted message to the console with pregnancy progress information.

Global Options

  • pregnancy.due_date: Date object setting default due date

  • pregnancy.person: Character string setting default person

See Also

set_due_date(), set_person()

Examples

# Current progress with explicit due date
# Note that output will depend on date the function is run
how_far(due_date = "2025-12-01")

# Progress on a specific date
how_far(on_date = "2025-11-01", due_date = "2025-12-01")

# With custom person
how_far(on_date = "2025-11-01", due_date = "2025-12-01", person = "Sarah")

# Set global options
date_opt <- getOption("pregnancy.due_date") # save current option
set_due_date("2025-12-01")
how_far()
options(pregnancy.due_date = date_opt) # return original option


pregnancy documentation built on Sept. 14, 2025, 5:09 p.m.