Pretty print time durations

I have a vector of seconds:

(z <- c(36, 36000, 360000, 36000000))

And I would like to convert them to a pretty durations. lubridate is the obvious place,

lubridate::duration(z, "seconds")
#[1] "36s"                     "36000s (~10 hours)"     
#[3] "360000s (~4.17 days)"    "36000000s (~1.14 years)"

which gives me exactly what I want (the bit in brackets). But the format.Duration() isn't exported
so it's a bit tricky getting the values I want.

could you say more about your issue ?
I'm not sure that a lack of exported function is any barrier to writing code...

exported_format <- lubridate:::format.Duration

The unofficial contract between package authors and users is that non-exported functions are liable to change without warning on notification. I can use that function, but it may change without warning.

Also if I used it in a package submitted to CRAN, it would bounce.

That is true indeed.
One option for you is that you could rerpoduce the source code in your own package (i.e. all exported and non exported function calls in lubridate that are those required for the format.Duration) and choose to export it in your package. Then you will be responsible not to alter its contracts.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.