Christoph Christoph - 4 months ago 20
R Question

Why is there no lubridate:::update function?

As said in the title: Why is there no such function? Or in a different way: What is the type of the function? When I type

?update
I get something from
stats
package, but there is a lubridate function as described here on page 7. There also seems to be a
lubridate:::update.Date
function, but I can't find any explanations for that function.

Backround: I use the function in a package and I only got it to work after I used the
Depends:
in the decription file. Initially I wanted to use
lubridate::update()
...

Answer

The lubridate package provides the methods lubridate:::update.Date() and lubridate:::update.POSIXt(). Those functions are not exported into the namespace, but I assume that, by means of function overloading, they are invoked when update() is applied to a POSIXor Date object when the lubridate library is loaded.

The help page ?lubridate:::update.POSIXt provides some information concerning the update function within the lubridate package:

Description

update.Date and update.POSIXt return a date with the specified elements updated. Elements not specified will be left unaltered. update.Date and update.POSIXt do not add the specified values to the existing date, they substitute them for the appropriate parts of the existing date.

Usage

## S3 method for class 'POSIXt'

update(object, ..., simple = FALSE)

The usage section and the examples in the help page indicate that these functions don't need to be addressed individually, as they are called by simply using update() when the lubridate library is loaded.

To inspect these functions one can type, e.g., lubridate:::update.POSIXt in the console (without passing arguments, and without the parentheses).