Skip to contents

This function calculates the time difference from a given initial time to the current time and prints it with a specified prefix. Optionally, it can also print a session summary.

Usage

CatDiff(
  InitTime,
  ChunkText = "Session summary",
  Prefix = "Completed in ",
  CatInfo = FALSE,
  Level = 0,
  Time = FALSE,
  ...
)

Arguments

InitTime

POSIXct; The initial time from which the difference is calculated.

ChunkText

character. The message printed as chunk info. Default value: Session summary. See: InfoChunk for more information.

Prefix

character; A prefix string to prepend to the printed time difference. Defaults to "Completed in ".

CatInfo

logical; If TRUE, prints a session summary using InfoChunk ("Session summary"). Defaults to FALSE.

Level

integer; the level at which the message will be printed. If e.g. Level = 1, the following string will be printed at the beginning of the message: " >>> ". Default is 0.

Time

logical; whether to include the time in the timestamp. Default is TRUE. If FALSE, only the text is printed.

...

Additional arguments for CatTime.

Value

The function is used for its side effect of printing to the console and does not return any value.

Author

Ahmed El-Gabbas

Examples

RefTime <- (lubridate::now() - lubridate::seconds(45))
CatDiff(RefTime)
#> Completed in 00:00:45
# Completed in 00:00:45 hours

RefTime <- (lubridate::now() -
    (lubridate::minutes(50) + lubridate::seconds(45)))
CatDiff(RefTime)
#> Completed in 00:50:45
# Completed in 00:50:46 hours

RefTime <- (lubridate::now() - lubridate::minutes(50))
CatDiff(RefTime)
#> Completed in 00:50:00
# Completed in 00:50:01 hours

RefTime <- (lubridate::now() - lubridate::minutes(70))
CatDiff(RefTime)
#> Completed in 01:10:00
# Completed in 01:10:00 hours

RefTime <- (lubridate::now() - lubridate::hours(4))
CatDiff(RefTime)
#> Completed in 04:00:00
# Completed in 04:00:01 hours

RefTime <- lubridate::now() -
  (lubridate::hours(4) + lubridate::minutes(50) + lubridate::seconds(45))
  CatDiff(RefTime)
#> Completed in 04:50:45
# Completed in 04:50:45 hours