bnosac / taskscheduleR

Schedule R scripts/processes with the Windows task scheduler.
331 stars 72 forks source link

Feature Request: print output from R to windows console #93

Open MoREpro opened 2 years ago

MoREpro commented 2 years ago

We use the package on our server for several tasks and this is working great. The only downside is, that several black console windows are shown, but it is not possible to see, if something is done successfully in the background or a problem has occured or even if this console is caused by the task created with rtaskscheduler. Is it possible to implement a feature, that output from R is shown in the windows console during execution? That would be wonderfull.

jwijffels commented 2 years ago

If I correctly understood, this is the same question/remark as https://github.com/bnosac/taskscheduleR/issues/87#issuecomment-1034781917

MoREpro commented 2 years ago

No, it is not the same question: I can see results of the tasks in the logfiles, but only if I know which task is writing the logfiles where and then go there and open the file. Me request is about showing the output of R in real time in the console which is open during processing. If a colleague has setup a R-task on the server, and I do not know about it, when I access the server I only see a emty console window without any information which programm caused this window and if something is still ongoing. I would like to see some output (messages, warnings) from R there, to know what is done and if the processing is going on sccessfully. I can create all these output in R but I do not know how to pipe it into the console window.

jwijffels commented 2 years ago

I meant that the solution is the same as what is depicted at https://github.com/bnosac/taskscheduleR/issues/87#issuecomment-1034781917

MoREpro commented 2 years ago

I might be able to change the location where to write the log-files. But how does this bring them to the console output? Is the console window I see from R or from the windows task scheduler? If it is the R console, why are the messages not shown by default, as it is when I run the srcipt from the GUI? I have some medium knowledge in R, but I'm not very experienced with Windows scripting and so on. Maybe you can give me a more detailed description, how to approach this problem?

jwijffels commented 2 years ago

Code https://github.com/bnosac/taskscheduleR/blob/ea6ebee197192c37950f92a321fa232ace3f3917/R/taskscheduleR.R#L146 is where the piping occurs. >> means append it to the log file 2>&1 means put all printed statements and errors and warnings in that log file, if you omit it, it just prints normal print statements to the console which is popped up instead of sending it to the log file. If you want to see progress, add options(echo = TRUE) in your R code. If you just want to see which processes are running, call taskscheduler_ls If your question is more like 'I'm using RStudio as a GUI and I'm expecting the progress to be printed there', I have to inform you that this R package has nothing to do with RStudio.

MoREpro commented 2 years ago

What you pointed out about the piping is exactly what I'was looking for. But I would need to print the output to the console and write it to the log file. Is that possible as well?

jwijffels commented 2 years ago

You can look at the code at the cronR package, there this is implemented https://github.com/bnosac/cronR/blob/master/R/cron_rscript.R#L36-L113