use_version and packageStartupMessage

I'm building an internal r package for my research team, and expect that it will be updated frequently over the next few months. I have a packageStartupMessage that spits out the version number and the date it was last updated. This is saved in a function called .onAttach which is stored in R/zzz.R.

I am looking at the usethis::use_version() function which seems nice for updating both the DESCRIPTION and files, is there an easy way to get it to also update my packageStartupMessage?

1 Like


I think the easiest way is to not hardcode the message's package version, but detect it during loading like this:

packageStartupMessage("The ggplot version loaded is: ", utils::packageVersion("ggplot2"))
The ggplot version loaded is: 3.3.2

Hope this helps,

1 Like

Following up on PJ's nice answer, you can also avoid hard-coding the last-updated date using utils::packageDate().

The one thing to be aware for packageDate() is that it requires the package is installed. Thus if you are developing your package with devtools::load_all(), it will return NA.

Thank you! Combining utils::packageDate and utils::packageVersion is working very nicely in the startup message. I appreciate the heads up about packageDate() and devtools::load_all() as well, mentioning that definitely saved me a lot of head scratching and debugging.

1 Like

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