Hello list, I suspect this is more a linux question than an R question, but I'll describe my situation in case anyone here knows of an elegant solution. I'm using Sweave and R to create thousands of customized reports. Within an R loop, I have R create a table.tex file using the CAT function which, for each iteration, creates a unique table.tex file in a subdirectory of the directory from which the master file is sourced. I have written a shell script called latexall that pdflatexs all the files in a given directory. I want to call latexall from within R using the SYSTEM command after I've created all my table.tex files. Later, the .pdfs of these tables are read into the document using the includegraphics command (The reason I'm creating tables this way is for two reasons: 1. xtable and latextable are limited, especially when one is producing complicated tables with \multicolumn headings and \raisebox commands that make the tables look nice; and 2. I've found that precompiling tables and then inputing them into a .tex file using the \includegraphics command takes much of the headache out of table production in LaTeX. In particular, tables that are too wide are easily dealt with by changing the scale factor. Float placement also seems easier to me when using \includegraphics) My bash shell script uses a standard for loop to loop over all the .tex file in a directory for f in *.tex The problem that I'm having is that I can't seem to direct latexall to the correct subdirectory without placing latexall in the subdirectory with all the table.tex files and hard coding that subdirectory into the the shell script before using the SYSTEM command to call latexall. for f in /home/directory/subdirectory/tables/*.tex Does anyone have an idea of how I can pass the appropriate path to my shell script from within R? I hope this makes sense. Any help greatly appreciated. Damian Damian Betebenner Educational Research, Measurement & Evaluation Lynch School of Education Boston College Chestnut Hill, MA 02467 (617) 552 4491
Fernando Henrique Ferraz P. da Rosa
2004-Dec-11 22:50 UTC
[R] Paths for Shell Scripts called from R
Damian Betebenner writes:> Hello list, > > I suspect this is more a linux question than an R question, but I'll describe my situation in case > anyone here knows of an elegant solution. >...> My bash shell script uses a standard for loop to loop over all the .tex file in a directory > > for f in *.tex > > The problem that I'm having is that I can't seem to direct latexall to the correct subdirectory without placing > latexall in the subdirectory with all the table.tex files and hard coding that subdirectory into the the shell > script before using the SYSTEM command to call latexall. > > for f in /home/directory/subdirectory/tables/*.tex > > Does anyone have an idea of how I can pass the appropriate path to my shell script from within R? >You could use the $* argument in your bash script, and then pass the argument via system(), on the call to the script. Suppose you have $ cat pdflatexall.sh #!/bin/bash for i in $1/*.tex; do echo pdflatex $i; done In R you could call by using: system('pdflatexall.sh /tmp') Works fine here: $ touch /tmp/bla1.tex /tmp/bla2.tex $ R> system('pdflatexall.sh /tmp')pdflatex /tmp/bla1.tex pdflatex /tmp/bla2.tex -- Fernando Henrique Ferraz P. da Rosa http://www.ime.usp.br/~feferraz
Damian Betebenner <damian.betebenner at bc.edu> writes:> Does anyone have an idea of how I can pass the appropriate path to > my shell script from within R?Anything wrong with just setting the PATH variable? E.g.> Sys.putenv(PATH=paste(Sys.getenv("PATH"),"/home/bs/pd/scripts",sep=":")) > system("SalesRank")Sun Dec 12 00:10:55 CET 2004 29605 -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907