Re: [R] Sweave, R and complex latex projects

2006-11-09 Thread Mark Wardle
All,

This is an update to my previous query on dealing with complex (complex
in my eyes anyway) LaTeX/Sweave projects. Based on the work of others,
please see my current thesis Makefile below. I didn't get Sweave and
LaTeX to cope with a master document in one directory, and chapters in
subdirectories, so instead I moved all individual chapter .tex and .Rnw
files into the same directory. The only reason for having directories in
the first place was to group all the charts and tables etc. and Sweave
makes that unnecessary anyway.

The other issue is that Sweave can interact with typeface settings in a
LaTeX document. One may avoid this by using the [noae] option, or just
making sure any typeface directives (including \usepackage{times}) come
after the \usepackage{Sweave} directive in your master LaTeX document.

I hope this is of help to someone else... No guarantees as I am not a
Makefile expert!

#
# Makefile
#
#
# Global project Makefile
#
#
# This makefile was based on
#
http://209.85.135.104/search?q=cache:-fU4UEn36AgJ:kriemhild.uft.uni-bremen.de/viewcvs/Makefile.rnoweb+makefile+sweave+latexhl=enct=clnkcd=10client=safari
# (The original file found on Google is no longer available and I
couldn't track a new version)
# This is credited to Johannes Ranke, based on work by Nicholas
Lewin-Koh and Rouben Rostmaian, and also from Deepayan Sarkar's email on
the R-help mailing list.
#
# The master document (document preamble, \include's the other files) is
thesis.tex
MASTER = thesis.pdf

# the master document depends on all of the tex files
RNWFILES = $(wildcard *.Rnw)
TEXFILES = $(wildcard *.tex)
DEPENDS = $(patsubst %.Rnw,%.tex,$(RNWFILES)) $(TEXFILES)


RERUN = (There were undefined references|Rerun to get
(citations|cross-references|the bars) (correct|right)|Table widths have
changed. Rerun LaTeX.|Linenumber reference failed)
RERUNBIB = No file.*\.bbl|Citation.*undefined

all: $(MASTER)

$(MASTER): $(DEPENDS)

%.tex: %.Rnw
R CMD SWEAVE '$'

%.pdf: %.tex
@pdflatex $
@egrep -c $(RERUNBIB) $*.log  (bibtex $*;pdflatex $); true
@egrep $(RERUN) $*.log  (pdflatex $) ; true
@egrep $(RERUN) $*.log  (pdflatex $) ; true

clean:
@rm -f *.aux *.log *.bbl *.blg *.brf *.cb *.ind *.idx *.ilg  \
  *.inx *.ps *.dvi *.toc *.out *.lot *~ *.lof *.ttt *.fff \
  *.eps *.pdf
@rm -f $(patsubst %.Rnw,%.tex,$(RNWFILES))


-- 
Dr. Mark Wardle
Clinical research fellow and Specialist Registrar in Neurology,
C2-B2 link, Cardiff University, Heath Park, CARDIFF, CF14 4XN. UK

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Sweave, R and complex latex projects

2006-10-16 Thread Friedrich Leisch
 On Sat, 14 Oct 2006 23:00:27 +0100,
 Mark Wardle (MW) wrote:

   Hello all,
   I've been able to use R very successfully to run simple statistics and
   generate the plots I require.

   I've been evaluating Sweave, and have hit upon a small problem that I
   don't seem to be able to workaround. Sweave runs very well for single
   file latex documents, but I have a complex thesis made up of several
   parts and chapters. These are arranged with a master latex file and
   subdirectories with \include-ed latex fragments representing those
   parts/chapters, and I don't seem to be able to get Sweave to work properly.

   I've tried a number of approaches, including converting the master
   document into a Snw file itself, or even generating chapters manually
   chapter by chapter using Sweave and then \includeing the result into
   the master tex file. Unfortunately for the latter attempt, the the latex
   generated doesn't prepend the required path to the filename, and so
   latex looks for the pdfs and tex files in the wrong place - it looks in
   the root directory (where the master tex file is located) rather than
   the chapter subdirectory where all the files have been generated.

   I hope I'm not missing something obviously documented, but I can't see
   it in the Sweave docs. Is there an option to prepend a pathname to the
   filename of Sweave generated TeX and PDF documents?

Yes, simply set prefix.string to a path, not only a filename. E.g.,

\SweaveOpts{prefix.string=figs/myfile}

will place all figures in subdir figs (you have to create the
directory first manually) and call the separate files myfile-XXX
where XXX is number or name of the chunk.

   Do people use Sweave for complex multi-file latex projects, and what is
   the best approach? I'm almost tempted to keep R and Latex separate, and
   continue to run a R script to generate all of the dynamic tables/charts
   which are then \inputed, but I was rather attracted to the whole
   Sweave approach.

I personally mostly use Makefiles as suggested by Deepayan.

In addition there is \SweaveInput{} which works similar to Latex's own
\input{} command. There currently is no equivalent of \include{}.

HTH,
Fritz

-- 
---
Prof. Dr. Friedrich Leisch 

Institut für Statistik  Tel: (+49 89) 2180 3165
Ludwig-Maximilians-Universität  Fax: (+49 89) 2180 5308
Ludwigstraße 33
D-80539 München http://www.stat.uni-muenchen.de/~leisch

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Sweave, R and complex latex projects

2006-10-16 Thread Friedrich Leisch
 On Sat, 14 Oct 2006 16:04:50 -0700,
 Deepayan Sarkar (DS) wrote:



   %.tex: %.Rnw
   echo library(tools); Sweave('$') | ${R_PROG} --vanilla --silent

Note that we now have R CMD Sweave (new in R 2.4.0) for this purpose.



Best,
Fritz

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Sweave, R and complex latex projects

2006-10-16 Thread Dirk Eddelbuettel

On 16 October 2006 at 11:28, Friedrich Leisch wrote:
|  On Sat, 14 Oct 2006 16:04:50 -0700,
|  Deepayan Sarkar (DS) wrote:
| 
| 
| 
|%.tex: %.Rnw
|echo library(tools); Sweave('$') | ${R_PROG} --vanilla --silent
| 
| Note that we now have R CMD Sweave (new in R 2.4.0) for this purpose.

It would have been nice if that followed convention and responded to --help
as suggested by 'R --help':


[EMAIL PROTECTED]:~$ R --help | tail -5

Please use 'R CMD command --help' to obtain further information about
the usage of 'command'.

Report bugs to [EMAIL PROTECTED].
[EMAIL PROTECTED]:~$ 

yet what we get is an error:

[EMAIL PROTECTED]:~$ R CMD Sweave --help
 library(utils); Sweave(--help)
Writing to file --help.tex
Processing code chunks ...
Error in SweaveReadFile(file, syntax) : no Sweave file with name '--help' found
Execution halted
[EMAIL PROTECTED]:~$ 


On the other hand:

[EMAIL PROTECTED]:~$ R CMD INSTALL --help | head -2
Usage: R CMD INSTALL [options] pkgs

[EMAIL PROTECTED]:~$ R --version
R version 2.4.0 (2006-10-03)
Copyright (C) 2006 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License.  For more information about
these matters, see http://www.gnu.org/copyleft/gpl.html.

[EMAIL PROTECTED]:~$ 



Dirk

-- 
Hell, there are no rules here - we're trying to accomplish something. 
  -- Thomas A. Edison

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Sweave, R and complex latex projects

2006-10-16 Thread Mark Wardle
Friedrich Leisch wrote:
 On Sat, 14 Oct 2006 23:00:27 +0100,
 Mark Wardle (MW) wrote:
 
Hello all,
...

 Yes, simply set prefix.string to a path, not only a filename. E.g.,
 ...

Many thanks for everyone's help on this (both on and off list). Working
perfectly now!

Now I just need help with   !

Only joking, although it will only be a matter of time!

Best wishes,

Mark

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Sweave, R and complex latex projects

2006-10-14 Thread Mark Wardle
Hello all,

I've been able to use R very successfully to run simple statistics and
generate the plots I require.

I've been evaluating Sweave, and have hit upon a small problem that I
don't seem to be able to workaround. Sweave runs very well for single
file latex documents, but I have a complex thesis made up of several
parts and chapters. These are arranged with a master latex file and
subdirectories with \include-ed latex fragments representing those
parts/chapters, and I don't seem to be able to get Sweave to work properly.

I've tried a number of approaches, including converting the master
document into a Snw file itself, or even generating chapters manually
chapter by chapter using Sweave and then \includeing the result into
the master tex file. Unfortunately for the latter attempt, the the latex
generated doesn't prepend the required path to the filename, and so
latex looks for the pdfs and tex files in the wrong place - it looks in
the root directory (where the master tex file is located) rather than
the chapter subdirectory where all the files have been generated.

I hope I'm not missing something obviously documented, but I can't see
it in the Sweave docs. Is there an option to prepend a pathname to the
filename of Sweave generated TeX and PDF documents?

Do people use Sweave for complex multi-file latex projects, and what is
the best approach? I'm almost tempted to keep R and Latex separate, and
continue to run a R script to generate all of the dynamic tables/charts
which are then \inputed, but I was rather attracted to the whole
Sweave approach.

Many thanks,

Mark

-- 
Dr. Mark Wardle
Clinical research fellow and Specialist Registrar in Neurology,
C2-B2 link, Cardiff University, Heath Park, CARDIFF, CF14 4XN. UK
email: [EMAIL PROTECTED]  [EMAIL PROTECTED]   OpenPGP key: 66896A39

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Sweave, R and complex latex projects

2006-10-14 Thread Deepayan Sarkar
On 10/14/06, Mark Wardle [EMAIL PROTECTED] wrote:
 Hello all,

 I've been able to use R very successfully to run simple statistics and
 generate the plots I require.

 I've been evaluating Sweave, and have hit upon a small problem that I
 don't seem to be able to workaround. Sweave runs very well for single
 file latex documents, but I have a complex thesis made up of several
 parts and chapters. These are arranged with a master latex file and
 subdirectories with \include-ed latex fragments representing those
 parts/chapters, and I don't seem to be able to get Sweave to work properly.

 I've tried a number of approaches, including converting the master
 document into a Snw file itself, or even generating chapters manually
 chapter by chapter using Sweave and then \includeing the result into
 the master tex file. Unfortunately for the latter attempt, the the latex
 generated doesn't prepend the required path to the filename, and so
 latex looks for the pdfs and tex files in the wrong place - it looks in
 the root directory (where the master tex file is located) rather than
 the chapter subdirectory where all the files have been generated.

 I hope I'm not missing something obviously documented, but I can't see
 it in the Sweave docs. Is there an option to prepend a pathname to the
 filename of Sweave generated TeX and PDF documents?

 Do people use Sweave for complex multi-file latex projects, and what is
 the best approach? I'm almost tempted to keep R and Latex separate, and
 continue to run a R script to generate all of the dynamic tables/charts
 which are then \inputed, but I was rather attracted to the whole
 Sweave approach.

You haven't told us what platform you are using, but makefiles are the
solution I would recommend if that's feasible. For example, the
Makefile in one of my presentations might look like

-

R_PROG = R-2.4
R_HOME = `${R_PROG} RHOME`
TPUTS = ${TEXINPUTS}:${R_HOME}/share/texmf/:tex/

TEX_COMPS = tex/defs tex/main
RNW_COMPS = faithful barley qqaspect

all: statgraphics.pdf

statgraphics.tex: $(TEX_COMPS:=.tex) $(RNW_COMPS:=.tex) tex/statgraphics.tex
cp tex/statgraphics.tex .

clean:
rm -f *.Rnw *.tex *.log *.dvi *.ps *.pdf *.R figs/* *~ */*~

%.Rnw: rnw/%.Rnw
ln -s $ .

%.tex: %.Rnw
echo library(tools); Sweave('$') | ${R_PROG} --vanilla --silent

%.R: %.Rnw
echo library(tools); Stangle('$') | ${R_PROG} --vanilla --silent

%.dvi : %.tex
TEXINPUTS=${TPUTS} texi2dvi -q -c $

%.ps : %.dvi
TEXINPUTS=${TPUTS} dvips -o -q $

%.pdf : %.tex
TEXINPUTS=${TPUTS} texi2dvi -c -q --pdf $

--

Things are slightly complicated because I tend to keep .tex and .Rnw
files in separate directories (but make a copy/link before running
Sweave or latex on them). After a make clean, the top-level directory
looks like:

[EMAIL PROTECTED]:statgraphics$ ls -R
.:
data  figs  Makefile  rnw  tex

./data:

./figs:

./rnw:
barley.Rnw faithful.Rnw  qqaspect.Rnw

./tex:
defs.tex  main.tex  statgraphics.tex

and

[EMAIL PROTECTED]:statgraphics$ grep input tex/*.tex
tex/main.tex:\input{faithful1}
tex/main.tex:\input{barley1}
tex/main.tex:\input{qqaspect}
tex/statgraphics.tex:\input{tex/defs}
tex/statgraphics.tex:\input{tex/main}

HTH,
-Deepayan

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.