Feature Request: timestamp in ISO8601-ish format

In RStudio you can add a timestamp to your code by just typing ts and then pressing Shift + Tab (is that officially documented somewhere?).

My comment on the timestamp format here was mostly tongue-in-cheek, but seriously

Tue Apr 24 10:40:55 2018 ------------------------------

is a pretty weird format.

I'd say something like

2018-04-24 10:40:55 Tue ------------------------------

would be much better. Or is there a particular reason for the format above?

1 Like

I am not using that feature, but that time format does look awfully weird to me, +1 for ISO

1 Like

ts is one of the many auto-expanding code snippets R Studio provides to get you started. Here's what the snippet definition looks like by default:

snippet ts
	`r paste("#", date(), "------------------------------\n")`

So really it's R + your computer's locale the C function ctime that's responsible for the date format :wink: You can edit the snippet to have it generate any date/time format you like by going to Preferences > Code > look for the tiny button at the bottom of the pane that says "Edit Snippets...".

Admittedly, the snippet editing area could be easier to find!

Snippets are a lot of fun... go forth and wield this mighty new power :muscle:


Ah, how did I not know that you could edit snippets? Really useful. Thank you @jcblum!

You're welcome! I do think the snippet editor flies under the radar — I'd love to see it appear in either the Code or Tools menu, myself.

1 Like

Thanks, this is great! I had read about snippets but completely forgotten about them.

So I guess I'd be fine with Sys.time() instead of date(). Still baffled though that someone would set the date()format as default for this snippet...

In case someone is looking for the snippet documentation: https://support.rstudio.com/hc/en-us/articles/204463668-Code-Snippets

1 Like

I'm totally with you on the oddness of that particular datetime format! But it seems to be venerable (see edit above).

Now I'm wondering... who chose that—of all things—as a fixed string datetime representation, and why?? :face_with_monocle: Sadly, cursory googling has not revealed anything like "an oral history of the genesis of C's time library", and this is getting seriously off-topic, so I think that's far enough down the :rabbit:hole for me!