How to insert current Timestamp in R?

Viewed 25

Is there a function to insert the current time among keyboard shortcuts? I didn't enter any syntax, but this code was generated.

# Mon Aug 22 17:02:58 2022 ------------------------------

I'd really like to know what this feature is. This feature will be very helpful for my R work.

1 Answers

Use Sys.time() + format:

format(Sys.time(), "%a %b %d %H:%M:%S %Y")
# [1] "Mon Aug 22 11:13:52 2022"

In Rstudio, you can use that to do a snippet. Go to Tools > Edit Code Snippets.

snippet currentDate
    # Date: `r paste(format(Sys.time(), "%a %b %d %H:%M:%S %Y"))` ------------------

And then, in the script, type currentDate + enter:

# Date: Mon Aug 22 11:17:18 2022 ------------------
Related