r - How to append date to the filename for logging -


i'm triggering r script via scheduler. r script causes errors (maybe due input problmens). after each run, r-out file history log. log super helpful in checking if went planed unfortunately gets overwritten every day. question is: how can different r-out file each day (e.g. date it)

best regards , thank you, phil

to generate filename includes current date, take output of sys.date() , use paste0to compose name of file including date.

maybe this:

filename <- paste0("r-out_", sys.date(), ".log") #> filename #[1] "r-out_2016-08-24.log" 

the format of date can changed format() if desired (thanks @konrad reminding this). instance, use format(sys.date(), "%d-%m-%y") obtain day-month-year form typically used, e.g., in europe:

filename <- paste0("r-out_", format(sys.date(), "%d-%m-%y"), ".log") 

we can use sink()to redirect console (standard) output of script file. in case script edited include definition of filename described above, followed command

sink(filename) 

this should inserted script file before displayed in standard output. possibly these 2 lines (the definition of filename , sink command) placed @ beginning, recommend using setwd(<pathtomyoutputdirectory>) first, specify output directory. after sink(filename) command, output displayed in console stored in file called according character string stored in filename. @ end of script restore default setting standard output using sink() without parameter (or, equivalently, sink(file = null)).


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -