I want a little helper to prepend a timestamp for each debug statement. I'm not looking to use a logger library. Here is the attempt:
tp = function(...) {
ts = format(Sys.time(), "%d.%m.%Y %H:%M:%OS")
m = paste('[',ts,']',str(...))
print(m)
}
When invoking the helper tp
to print the columns of a data.frame
:
tp(names(df))
The intended output is this:
[ 04.03.2020 19:35:00.345 ] country state day dt confirmed recovered deaths
But the actual output is:
chr [1:7] "country" "state" "day" "dt" "confirmed" "recovered" "deaths"
[1] "[ 04.03.2020 19:35:00.345 ] "
Note that I added
str(...)
because otherwise the output is one line per column element. Instead the output should keep the printing on one line: maybe via joining the collection items some way? I could use some help on cleaning this up.