Re: [Rd] Working with Sweave: inverse search?

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Thu 18 Jan 2007 - 14:52:51 GMT

I've now packaged up the Sweave inverse search package, and made the prototype available on my web page

http://www.stats.uwo.ca/faculty/murdoch/software

as patchDVI_0.2.tar.gz and patchDVI_0.2.zip. I don't know of any bugs in those, but I'd like to hear about them.

To enable the inverse search, you need an \SweaveOpts line in the .Rnw file with "concordance=TRUE".

I normally use MikTeX, so to make my life easier I wrote a little SweaveMiktex() function and put it in the package. Using that package in Windows, the following batch file processes Sweave, runs latex, patches the .dvi, and runs the previewer:

echo library(patchDVI);SweaveMiktex('%2', '%3.tex') | Rterm --slave yap -1 -s"%1%2" %3.dvi

It needs to be called with three parameters:

%1 - the current line number in the editor; yap will jump to that location

%2 - the name of the current file in the editor; if it's *.tex, then
Sweave will be skipped, but the patching will still be done (because some other file in the project might be a .Rnw file). If not, the file is run through Sweave first.

%3 - the base name of the file (no extension) to send to latex.

For example, if I am on line 100 of a chapter called syntax.Rnw in a book called programming.tex, I would call this file with args

100 syntax.Rnw programming

If you're using some other TeX package, the SweaveMiktex function might still work, but it's likely the script to run it and the previewer would have to change.

If you have a completely different work flow, the steps you need to implement are these:

  1. Put the \SweaveOpts{concordance=TRUE} line into your .Rnw file.
  2. Run the patchDVI version of Sweave() on your file.
  3. Run latex to produce a .dvi file.
  4. Run the patchDVI function on the .dvi file to patch it.
  5. Run your previewer, with options telling it you want to see a particular line in the .Rnw file.

In a big project, you only need to run Sweave on those .Rnw files that have changed; the information linking to the original source is output in a file in the same place figures from the Sweave output would be saved, e.g. in the example above, as "syntax-concordance.tex".

The format of the concordance is very likely to change as patchDVI evolves, so you'll want to re-run Sweave if you update your patchDVI package.

Duncan Murdoch



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri Jan 19 02:08:31 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 18 Jan 2007 - 17:31:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.