[R] Debugging a program written in the R language

Thomas L Jones DrJones at alum.MIT.edu
Wed Mar 8 22:12:35 CET 2006


>From Tom:

The subject is debugging a program written in the R language,under 
Windows. (Sorry, but I do not know either the Apple OS or *nix.) A 
computer program will usually not work on the first try, if only 
because of the risk of typos. Instead, it must be debugged. Roughly, 
here is the sequence:

(1) One codes a program using the R language,  and stores it on the 
hard drive, using some particular editor.

(2) The program is fed to the R software, together with test data, 
etc.

(3) A test computation is run and bugs are spotted.

(4) The program is corrected, using an editor, and the revised version 
is stored on the hard drive.

(5) The sequence goes back to step (2) and is repeated until the 
program hopefully works.

Unfortunately, the documentation doesn't really explain how to do all 
of this, or if it is explained in the documentation, I can't find it.

Reading between the lines a bit, I infer that you are supposed to be 
able to use something called a History file, then sort of work 
backward in the code and make corrections. I never got it to work for 
me. Also, it is unclear how you would handle code entered six weeks or 
six months ago.

That is the bad news; the good news is that some kind soul told me 
about a key trick; prepare the program in Windows text format (.txt) 
and copy it and paste it into the console. The program will now run 
from a user-defined "wrapper" or "driver" function.

I am aware that there is an editor called Emacs which you can use if 
you are a member of the *nix community, which I am not.

Question: How are you -supposed- to debug a program which you have 
written in the R language?

Tom
Thomas L. Jones, Ph.D., Computer Science




More information about the R-help mailing list