Skip to contents

This function prints a given text followed by the current time (and optionally the date) to the console. It allows for customization of the time zone, the inclusion of the date, and the number of newline characters to print after the message.

Usage

CatTime(
  Text = "",
  NLines = 1L,
  Time = TRUE,
  Bold = FALSE,
  Red = FALSE,
  Date = FALSE,
  TZ = "CET",
  Level = 0L,
  ...
)

Arguments

Text

character; the text to print before the timestamp. If empty (default), only the timestamp is printed.

NLines

integer; the number of newline characters to print after the message. Default is 1.

Time

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

Bold

logical; whether to print the text in bold. Default is FALSE.

Red

logical; whether to print the text in red. Default is FALSE.

Date

logical; whether to include the date in the timestamp. Only effective if Time is TRUE. Default is FALSE, meaning only the time is printed. If TRUE, the date is printed in the format "%d/%m/%Y %X".

TZ

character; the time zone to use for the timestamp. Default is CET.

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.

...

additional arguments passed to cat.

Value

The function is called for its side effect of printing to the console.

Author

Ahmed El-Gabbas

Examples

CatTime()
#> 03:13:06

CatTime(Date = TRUE)
#> 08/02/2025 03:13:06

CatTime("Time now")
#> Time now -  03:13:06

CatTime("Time now", Date = TRUE)
#> Time now -  08/02/2025 03:13:06

# The use of levels
{
  CatTime("Task 1")
  CatTime("subtask L1", Level = 1)
  CatTime("subtask L2", Level = 2)
  CatTime("subtask L3", Level = 3)
}
#> Task 1 -  03:13:06
#>   >>>  subtask L1 -  03:13:06
#>   >>>  >>>  subtask L2 -  03:13:06
#>   >>>  >>>  >>>  subtask L3 -  03:13:06