2

I have an Rscript that I run using crontab, that take a long time to complete. I'm appending the output of it to a file, and have littered the code with print statements to track the progress of the script as it's running in the background.

This works, but I'm getting tired of adding more and more print statements. What I really want is to see what command it's running together with the output it generates. E.g. when running the following script:

$ cat test.r
#!/bin/env Rscript

Sys.sleep(10)
3+2

I'd like the output to somehow be

> Sys.sleep(10)
> 3+2
[1] 5

i.e. exactly what I'd see had I run it interactively.

Any ideas?

eddi
  • 49,088
  • 6
  • 104
  • 155

1 Answers1

2

Add the following to the top of your script:

options(echo = TRUE)

From ?options

echo: logical. Only used in non-interactive mode, when it controls whether input is echoed. Command-line option --slave sets this to FALSE, but otherwise it starts the session as TRUE.

Dason
  • 60,663
  • 9
  • 131
  • 148