Home > OS >  R beepr plays way too early
R beepr plays way too early

Time:03-03

I'm not sure I can include reproducible code on this, given there's 4,000 lines of code and that may be part of the problem, but let me try to explain my question the best I can:

I love using beepr to play an audible sound when a bunch of code is done processing. If my computer is taking a while to run it, I'll go look at a different screen or do something else in the room when its thinking.

I have a large .rmd file. Its 4187 lines long and beep() is on line 4185. I made sure it was nowhere else in the document using ctrl f. When I "run all", the beep goes off when I'm about this far through the document:
enter image description here

And then it'll continue thinking for another few minutes before its done. This defeats the entire purpose of beepr().

So I guess my question is: is this a known problem? Is there anything particular to a .rmd document that does this? Any known fixes?

CodePudding user response:

{knitr} manpage says:

This function takes an input file, extracts the R code in it according to a list of patterns, evaluates the code and writes the output in another file.

So the thing you are observing is due to the fact all R code in the .rmd gets evaluated before the whole process is finished. The sound plays when the beepr line is executed, since this will happen (rcode chunk) before the document is processed by pandoc (or similar) i would just advise you to put the beeper outside of the .rmd itself to trigger it after the process finished. write a 3 line r sript:

knit("my.rmd")
Sys.sleep(1)
beepr() 

This makes sure the beep will only start after the document is created (Sys.sleep just to make sure and prob. not necessary)

  • Related