Can we pause the debugging process in R? - r

I wrote code which has been running for more than 12 hours and I run it by mtrace() and go() function (from the debug package). Now I want to pause this and go through the remaining process myself by pressing enter, is there a way to do that?
mtrace(main)
F<-main()
go()

Related

How to interrupt process in Rstudio elegantly?

Maybe it's because I'm too careless and often write the wrong code when dealing with big data. I tried to click the stop button(the red one in Rstudio), ctrl + c, ctrl+z, none of them can interrupt the process, and in the end I have to terminate the ```rsession`` and Rstudio in the terminal. Is ther anything else I can do? (I am using dplyr)
You can press esc and wait the until job is cancelled

AutoIt Scripting for an External CLI Program - eac3to.exe

I am attempting to design a front end GUI for a CLI program by the name of eac3to.exe. The problem as I see it is that this program sends all of it's output to a cmd window. This is giving me no end of trouble because I need to get a lot of this output into a GUI window. This sounds easy enough, but I am begining to wonder whether I have found one of AutoIt's limitations?
I can use the Run() function with a windows internal command such as Dir and then get the output into a variable with the AutoIt StdoutRead() function, but I just can't get the output from an external program such as eac3to.exe - it just doesn't seem to work whatever I do! Just for testing purposesI I don't even need to get the output to a a GUI window: just printing it with ConsoleWrite() is good enough as this proves that I was able to read it into a variable. So at this stage that's all I need to do - get the text (usually about 10 lines) that has been output to a cmd window by my external CLI program into a variable. Once I can do this the rest will be a lot easier. This is what I have been trying, but it never works:
Global $iPID = Run("C:\VIDEO_EDITING\eac3to\eac3to.exe","", #SW_SHOW)
Global $ScreenOutput = StdoutRead($iPID)
ConsoleWrite($ScreenOutput & #CRLF)
After running this script all I get from the consolWrite() is a blank line - not the text data that was output as a result of running eac3to.exe (running eac3to without any arguments just lists a screen of help text relating to all the commandline options), and that's what I am trying to get into a variable so that I can put it to use later in the program.
Before I suggest a solution let me just tell you that Autoit has one
of the best help files out there. Use it.
You are missing $STDOUT_CHILD = Provide a handle to the child's STDOUT stream.
Also, you can't just do RUN and immediately call stdoutRead. At what point did you give the app some time to do anything and actually print something back to the console?
You need to either use ProcessWaitClose and read the stream then or, you should read the stream in a loop. Simplest check would be to set a sleep between RUN and READ and see what happens.
#include <AutoItConstants.au3>
Global $iPID = Run("C:\VIDEO_EDITING\eac3to\eac3to.exe","", #SW_SHOW, $STDOUT_CHILD)
; Wait until the process has closed using the PID returned by Run.
ProcessWaitClose($iPID)
; Read the Stdout stream of the PID returned by Run. This can also be done in a while loop. Look at the example for StderrRead.
; If the proccess doesnt end when finished you need to put this inside of a loop.
Local $ScreenOutput = StdoutRead($iPID)
ConsoleWrite($ScreenOutput & #CRLF)

R: I fail to pause my code

I am trying to pause my code for a little while, time for me to observe the plots.
I tried:
print('A')
something = readline("Press Enter")
print('B')
print('C')
, then there is no pause, the line print('B') is fed to readline and get stored into something and therefore only A and C got printed on the screen. Note that if I add an empty line between Something = readline("Press Enter") and print("B"), then print("B") get printed on the screen but still the console doesn't allow the user to press enter before continuing.
And I tried:
print('A')
Sys.sleep(3)
print('B')
print('C')
The program waits 3 seconds before starting and then run "normally" without doing any pause between print('A') and print('B').
What do I missunderstand?
Here is my R version: R 3.1.1 GUI 1.65 Snow Leopard build (6784)
The problem with readline is that if you paste your script into an R console, or execute it from eg Rstudio, the redline function is read and then the next line of the script is read in as the console entry, which in your case sets the value of something to print('B).
An easy way to get around this is to stick your entire code in a function, then call the function to run it. So, in your case:
myscript = function(){
print('A')
something = readline(prompt = "Press Enter")
print('B')
print('C')
}
myscript()
The output of this for me (in Rstudio, with R version 3.1.1):
[1] "A"
Press Enter
[1] "B"
[1] "C"
This has always felt like a bit of a hack to me, but it's essentially what the readline documentation recommends in its example.
I've never used sleep in my code, so I can't help you there.
Edit to clarify based on comments: This will only work if myscript() is the very last line of your script, or if it is manually entered into the console after running the script to generate the function. Otherwise, you will run into the same problem as before- the next line of code will be automatically entered.

Refresh *R dired* buffer after executing command in inferior ESS process

I'd like to advise the inferior-ess-send-input interactive function to call my function which refreshes the *R dired* buffer automatically. I've tried using after and around as classes. For example:
(defadvice inferior-ess-send-input (around ess-revert-rdired-after-send activate)
ad-do-it
(call-interactively 'ess-revert-rdired-buffer))
I've also tried using after and even changed the source code of ESS to create a post-run hook. All of them had the same issue. I've even defined a new function which calls one after the other.
But I keep getting the message:
ess-error: ESS process not ready. Finish your command before trying again.
comming from ess-command. For some reason, adding this advice makes sprocess busy. Any ideas?
P.S.
Here the function is (work in progress):
(defun ess-revert-rdired-buffer ()
"If the buffer is live, update it. If it isn't start it."
(interactive)
(save-selected-window
(if (buffer-live-p (get-buffer "*R dired*"))
(save-excursion
(with-current-buffer "*R dired*"
(revert-buffer)))
(ess-rdired))))
I discovered that waiting 0.05 seconds was enough time for the process to get ready.

How to determine the execution stop event of a program

I have a script which logs certain data when a benchmark (some c code like matrix multiplication) runs.
I want to first start the log script when benchmark starts, this is easy since I can just start the binary from the log script and then proceed to log the info.
But the real question is when do I stop it? The benchmark can stop at anytime (The log script shouldn't stop the benchmark). How do I get the info/variable which can be used in the log script to stop it when benchmark program stops?
I was thinking if I can use PID of the benchmark, but then thought there should be a better solution than searching and using the PID.
Thanks!
Perhaps you could try something like this:
#!/bin/bash
#
# Your main script
#
# Run your log program in background
your_log_program &
# The PID of last background program
LOGPROGRAMPID=$!
# Install EXIT trap (EXIT is a bash's special event)
trap 'kill -15 $LOGPROGRAMPID; exit 0' EXIT
# In foreground launch your benchmark program
run_your_benchmark_program
# When benchmark program ends your trap will be launched and it will kill your log
# program.

Resources