2009-04-01

Sweave.sh update

A local version of Sweave.sh has been updated:
  • fixed a buglet that caused weaving the file twice when --weaver option was used --> this led to a change how caching is now invoked (--cache invokes cacheSweave package, while --cache --weaver or --weaver invokes weawer package)
  • quoting *APP variables to ensure that things work in case of "bad" filenames, i.e., spaces in filenames etc.
  • small changes in the documentation
I will take this opportunity to show how PDFAPP and PSAPP environmental variables can be used "open" options. This is an example from the help, which shows that these two variables need to be exported in order to have any effect. I am still fiddling whith how to provide any meaningfull defaults. My defaults are 'acroread' for PDF and 'gv' for Postscript, but I am happy to set any other more meaningfull defaults if there will be enough demand!
# Create PDF via the texi2dvi (latex) tool and open
# a produced file
Sweave.sh -otld file.Rnw

# Create PDF via the texi2dvi (latex) tool and open
# a produced file with a "non-standard" viewer
Sweave.sh -otld=acrobat file.Rnw

# ... or
export PDFAPP=acrobat
Sweave.sh -otld file.Rnw
This is an example of launcing Acrobat Reader installed on MS Windows, while Sweave.sh is launched within Cygwin X-terminal:
export PDFAPP=/cygdrive/c/Program\ Files/Adobe/Reader\ 9.0/Reader/AcroRd32.exe
Sweave.sh -otld file.Rnw

7 comments:

은서애비 said...

I tried to link lyx and sweave following your suggestions in the "Using Sweave with Lyx" article but got strange error when I ran 'test.lyx' file or any other 'lyx' example files. When I traced the error message, it turned out that it was because the 'Sweave.sh' file in the bin directory coming with the R distribution was formatted in DOS mode (which puts two characters for newline---'\r\n'--- instead of one character---'\n'--- as in Unix mode) and the shell command I was using from Cygwin system didn't know what to do with the '\r' character. So when I changed the format of 'Sweave.sh' (and actually the 'Stangle.sh' as well) to the Unix mode, the problem was gone! I leave this notice to be of help in case someone else may experience troubles similar to mine...

Gorjanc Gregor said...

Thank you for the heads up! I never had a problem you are dscribing, but it os good to have this issue in mind.

Thanks, gg

Shige said...

Hi Gregor,

Thanks for the script, it is really helpful. Have you tried to integrate your script with Emacs? I will be really convenient if one can edit a .Rnw file, and then do the weaving, latexing, and pdf viewing with one command.

Gorjanc Gregor said...

I like Emacs, but I do not use it very often lately, since I often have to switch between the Linux and MS Windows. Therefore, I fallback to the editor that is just there, because I had hard time in the past to have the same setup for Emacs on both Linux and MS Windows. Has this changed lately?

Regarding the Sweave.sh support in Emacs. I always had a hard time to understand Emacs LISP so I will leave that to someone else. However, I wonder if that would be very usefull given the fact that there are quite some options that Sweave.sh accepts and very different ways to compile LaTeX docs.

Matthieu said...

Hi

I tried to use the last updated version you put but had a problem (I call the shellé from withi Kile):

cd '/home/mat/Repertoires/svn/InrusdMTAR'
***** Sweave.sh -ld 'RegimeSwitichingINRUSD.Rnw'
*****
/bin/bash: /usr/local/bin/Sweave.sh : /bin/bash^M : mauvais interpréteur: Aucun fichier ou dossier de ce type

This is definitely a problem with the new one (Time-stamp: <2009-01-21 23:33:00 ggorjan>) as replacing by old one (Time-stamp: <2008-11-26 11:11:55 ggorjan>) then everything is ok.

I supspect it's just an encoding problem... did I do something wrong?

Thanks

Gorjanc Gregor said...

This is likely do to the DOS and UNIX line endings. Use dos2unix or equivalent program to fix line endings.

Anonymous said...

dos2unix solved the issue... thanks!!