Ptit_Bleu
2007-Dec-10 16:25 UTC
[R] Sweave : change value in rnw file to generate multiple "single" reports ?
Hello, I'm still trying to make the life of my colleagues easier. Nice, isn't it ? At the moment, I'm looking for a way to generate multiple "single report". In fact I have a .rnw file which send a query to a MySQL database (rs<-dbSendQuery(con, statement="select * from treatdata where name='Device1'") But of course my colleagues have many devices and don't want to enter the rnw file to change the name of the device. Is there a way to pass arguments to Sweave like Sweave("myfile.rnw", namevar="Device2") and it will change namevar by Device2 into the file myfile.rnw before creating the .tex file ? Or is it possible to do it via another language, that is: loading the rnw file, modifying it, saving it and finally calling Sweave ? Whatever the solution, I need you help. In advance thank you. Ptit Bleu. -- View this message in context: http://www.nabble.com/Sweave-%3A-change-value-in-rnw-file-to-generate-multiple-%22single%22-reports---tp14256204p14256204.html Sent from the R help mailing list archive at Nabble.com.
Gabor Grothendieck
2007-Dec-10 16:44 UTC
[R] Sweave : change value in rnw file to generate multiple "single" reports ?
The ability to pass arguments on the R CMD Sweave line is something I would very much like to have as well. Currently you need to create a shell or batch file that accepts the arguments, place those into environment variables using shell or batch code and then run sweave. R code in your swevae file would then read the environment variables using Sys.getenv. On Dec 10, 2007 11:25 AM, Ptit_Bleu <ptit_bleu at yahoo.fr> wrote:> > Hello, > > I'm still trying to make the life of my colleagues easier. Nice, isn't it ? > At the moment, I'm looking for a way to generate multiple "single report". > In fact I have a .rnw file which send a query to a MySQL database > (rs<-dbSendQuery(con, statement="select * from treatdata where > name='Device1'") > > But of course my colleagues have many devices and don't want to enter the > rnw file to change the name of the device. > > Is there a way to pass arguments to Sweave like Sweave("myfile.rnw", > namevar="Device2") and it will change namevar by Device2 into the file > myfile.rnw before creating the .tex file ? > Or is it possible to do it via another language, that is: loading the rnw > file, modifying it, saving it and finally calling Sweave ? > > Whatever the solution, I need you help. In advance thank you. > Ptit Bleu. > -- > View this message in context: http://www.nabble.com/Sweave-%3A-change-value-in-rnw-file-to-generate-multiple-%22single%22-reports---tp14256204p14256204.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org 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. >
ONKELINX, Thierry
2007-Dec-10 16:49 UTC
[R] Sweave : change value in rnw file to generate multiple "single"reports ?
I think something like this would work. Change your query to rs <- dbSendQuery(con, statement = paste("select * from treatdata where name='", whichDevice,"'", sep = "")) And then create a script like. whichDevice <- "Device1" Sweave("myfile.rnw") whichDevice <- "Device2" Sweave("myfile.rnw") HTH, Thierry ------------------------------------------------------------------------ ---- ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 Thierry.Onkelinx op inbo.be www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -----Oorspronkelijk bericht----- Van: r-help-bounces op r-project.org [mailto:r-help-bounces op r-project.org] Namens Ptit_Bleu Verzonden: maandag 10 december 2007 17:26 Aan: r-help op r-project.org Onderwerp: [R] Sweave : change value in rnw file to generate multiple "single"reports ? Hello, I'm still trying to make the life of my colleagues easier. Nice, isn't it ? At the moment, I'm looking for a way to generate multiple "single report". In fact I have a .rnw file which send a query to a MySQL database (rs<-dbSendQuery(con, statement="select * from treatdata where name='Device1'") But of course my colleagues have many devices and don't want to enter the rnw file to change the name of the device. Is there a way to pass arguments to Sweave like Sweave("myfile.rnw", namevar="Device2") and it will change namevar by Device2 into the file myfile.rnw before creating the .tex file ? Or is it possible to do it via another language, that is: loading the rnw file, modifying it, saving it and finally calling Sweave ? Whatever the solution, I need you help. In advance thank you. Ptit Bleu. -- View this message in context: http://www.nabble.com/Sweave-%3A-change-value-in-rnw-file-to-generate-mu ltiple-%22single%22-reports---tp14256204p14256204.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help op r-project.org 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.
Uwe Ligges
2007-Dec-10 16:52 UTC
[R] Sweave : change value in rnw file to generate multiple "single" reports ?
Within or before SWeave, you can use R. Hence you can write some R function that first changes the rnw and runs SWeave thereafter, or even better, write something in your SWeave code that reads a user customized variables, e.g. from an environment variable or from some text file. Uwe Ligges Ptit_Bleu wrote:> Hello, > > I'm still trying to make the life of my colleagues easier. Nice, isn't it ? > At the moment, I'm looking for a way to generate multiple "single report". > In fact I have a .rnw file which send a query to a MySQL database > (rs<-dbSendQuery(con, statement="select * from treatdata where > name='Device1'") > > But of course my colleagues have many devices and don't want to enter the > rnw file to change the name of the device. > > Is there a way to pass arguments to Sweave like Sweave("myfile.rnw", > namevar="Device2") and it will change namevar by Device2 into the file > myfile.rnw before creating the .tex file ? > Or is it possible to do it via another language, that is: loading the rnw > file, modifying it, saving it and finally calling Sweave ? > > Whatever the solution, I need you help. In advance thank you. > Ptit Bleu.
Dieter Menne
2007-Dec-10 16:53 UTC
[R] Sweave : change value in rnw file to generate multiple "single" reports ?
Ptit_Bleu <ptit_bleu <at> yahoo.fr> writes: ...> Is there a way to pass arguments to Sweave like Sweave("myfile.rnw", > namevar="Device2") and it will change namevar by Device2 into the file > myfile.rnw before creating the .tex file ? > Or is it possible to do it via another language, that is: loading the rnw > file, modifying it, saving it and finally calling Sweave ?You can set an environment variable in the system (SET DELTA=...), and read it in from R: Sys.getenv("DELTA") Works for Windows with a rather inconsistent implementation of environment strings, so it should work the better with Linux. Dieter
Duncan Murdoch
2007-Dec-10 16:56 UTC
[R] Sweave : change value in rnw file to generate multiple "single" reports ?
On 12/10/2007 11:25 AM, Ptit_Bleu wrote:> Hello, > > I'm still trying to make the life of my colleagues easier. Nice, isn't it ? > At the moment, I'm looking for a way to generate multiple "single report". > In fact I have a .rnw file which send a query to a MySQL database > (rs<-dbSendQuery(con, statement="select * from treatdata where > name='Device1'") > > But of course my colleagues have many devices and don't want to enter the > rnw file to change the name of the device. > > Is there a way to pass arguments to Sweave like Sweave("myfile.rnw", > namevar="Device2") and it will change namevar by Device2 into the file > myfile.rnw before creating the .tex file ?Not as far as I know, but you could wrap Sweave() in another function that uses save() to write a file of variables, and start your .Rnw file with load("file.Rdata").> Or is it possible to do it via another language, that is: loading the rnw > file, modifying it, saving it and finally calling Sweave ?Surely yes, there are lots of ways to automatically edit a text file. Duncan Murdoch> > Whatever the solution, I need you help. In advance thank you. > Ptit Bleu.
Greg Snow
2007-Dec-10 21:04 UTC
[R] Sweave : change value in rnw file to generate multiple "single" reports ?
Others have given some good advice, and what works best for you will depend on exactly what you want to do and how you think about the problem. Here are just a couple of other ideas to throw into the mix. If you want to edit the .rnw file, then the tools sed, awk, or perl (or probably several others) can all do this quite easily. For example if you have a file (base.rnw) that has MYDEVICE everywhere that you want to replace with Device2 or whatever then the following command at a command prompt will create a new file (dev2.rnw) that is a copy of base.rnw with all occurences of MYDEVICE replaced with Device2: perl -pe "s/MYDEVICE/Device2/g" base.rnw > dev2.rnw Another tool that you may want to learn is "make". You can set up a makefile that shows how each file relates to the next in a chain of steps, then just type something like: make device2.pdf At the command line and it will automatically make the changes to your .rnw file and possibly to data or other files involved, then run all the steps needed to create device2.pdf, then deletes all the intermediate files that you don't need (device2.dvi, ...). It also has the benefit of being able to update all the appropriate files when you update a data file, script file, or .rnw file. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org (801) 408-8111> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Ptit_Bleu > Sent: Monday, December 10, 2007 9:26 AM > To: r-help at r-project.org > Subject: [R] Sweave : change value in rnw file to generate > multiple "single" reports ? > > > Hello, > > I'm still trying to make the life of my colleagues easier. > Nice, isn't it ? > At the moment, I'm looking for a way to generate multiple > "single report". > In fact I have a .rnw file which send a query to a MySQL > database (rs<-dbSendQuery(con, statement="select * from > treatdata where > name='Device1'") > > But of course my colleagues have many devices and don't want > to enter the rnw file to change the name of the device. > > Is there a way to pass arguments to Sweave like Sweave("myfile.rnw", > namevar="Device2") and it will change namevar by Device2 into > the file myfile.rnw before creating the .tex file ? > Or is it possible to do it via another language, that is: > loading the rnw file, modifying it, saving it and finally > calling Sweave ? > > Whatever the solution, I need you help. In advance thank you. > Ptit Bleu. > -- > View this message in context: > http://www.nabble.com/Sweave-%3A-change-value-in-rnw-file-to-g > enerate-multiple-%22single%22-reports---tp14256204p14256204.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org 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. >
Ptit_Bleu
2007-Dec-11 15:04 UTC
[R] Sweave : change value in rnw file to generate multiple "single" reports ?
Dear Uwe, Could you please give me the name of the function to open, to modify and to save a r script ? Just the name and I will look for the way to use them. And if you have a link explaining how to use user customized variables from an environment variable, it will be very helpful (as it is completely new to me). Thanks in advance, Ptit Bleu. ------------------------------------------------ Within or before SWeave, you can use R. Hence you can write some R function that first changes the rnw and runs SWeave thereafter, or even better, write something in your SWeave code that reads a user customized variables, e.g. from an environment variable or from some text file. Uwe Ligges -- View this message in context: http://www.nabble.com/Sweave-%3A-change-value-in-rnw-file-to-generate-multiple-%22single%22-reports---tp14256204p14275809.html Sent from the R help mailing list archive at Nabble.com.
Seemingly Similar Threads
- Must be easy, but haven't found the function (numerical integration)
- find a sequence of characters in a vector
- Best way to select good points in a noisy signal ?
- How to combine xtable and minipage with Sweave ?
- Friendly way to link R - MySQL and non-(R and Mysql) users ?