An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111107/2dc1ac21/attachment.pl>
R in batch mode packages loading question
6 messages · Duncan Murdoch, PALMIER Patrick - CETE NP/INFRA/TRF, Andrew Ziem +1 more
On 07/11/2011 5:49 AM, PALMIER Patrick (Responsable de groupe) - CETE
NP/TM/ST wrote:
Hello, I use R in batch mode. Each time, I execute a script, R is loading each packages I need in my script. That's Ok But, I had to execute many scripts , and each time R is re-loading the corresponding packages, which take to much time Is it possible ask R to load the packages only once, and stay in memory in background for further scripts, which would avoid to load the packages in each script, or if you have another solution that need to only load packages once in the first scripts, so that further scripts do not need to load these packages too.
Write one script that has a sequence of calls to source() to run the other scripts. You'll need to be careful that unintentional leftover objects and settings from one script don't affect the others; you may also want to use the "echo=TRUE" option when you source, so you see the commands as they are executed. Duncan Murdoch
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111107/c403ab2e/attachment.pl>
Thank you for your response, but this is not exactly what I need We are working on a tool that automatically generate R scripts adapted to our surveys databases. When we want to do a table, we select interactively fields, associated labels, functions for an automatic crosstable for example Then, the tool executes R in batch mode with the script produced by the tool The "many scripts" correspond to the many crosstables people want to do. It is not possible produce these different scripts and execute all of them in a unique script with source. For example, people want to do a crosstable, the tool produce a r script that generate the result. Then, the user want to do the same crosstable but on a subset or with different labels. Then, the tools produces another r script, and execute R which reloads at each time all the neeeded packages. Is there a way to avoid this thing and to load packages only once? Than you in advance *Patrick PALMIER** *** Le 07/11/2011 15:20, > Duncan Murdoch (par Internet) a ?crit :
On 07/11/2011 5:49 AM, PALMIER Patrick (Responsable de groupe) - CETE NP/TM/ST wrote:
Hello, I use R in batch mode. Each time, I execute a script, R is loading each packages I need in my script. That's Ok But, I had to execute many scripts , and each time R is re-loading the corresponding packages, which take to much time Is it possible ask R to load the packages only once, and stay in memory in background for further scripts, which would avoid to load the packages in each script, or if you have another solution that need to only load packages once in the first scripts, so that further scripts do not need to load these packages too.
Write one script that has a sequence of calls to source() to run the other scripts. You'll need to be careful that unintentional leftover objects and settings from one script don't affect the others; you may also want to use the "echo=TRUE" option when you source, so you see the commands as they are executed. Duncan Murdoch
Try the fork() function in the package multicore (if your system supports it) Andrew -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of PALMIER Patrick (Responsable de groupe) - CETE NP/TM/ST Sent: Monday, November 07, 2011 3:49 AM To: r-help at r-project.org Subject: [R] R in batch mode packages loading question Hello, I use R in batch mode. Each time, I execute a script, R is loading each packages I need in my script. That's Ok But, I had to execute many scripts , and each time R is re-loading the corresponding packages, which take to much time Is it possible ask R to load the packages only once, and stay in memory in background for further scripts, which would avoid to load the packages in each script, or if you have another solution that need to only load packages once in the first scripts, so that further scripts do not need to load these packages too. Thanks in advance
*Patrick PALMIER** **Centre d'?tudes Techniques de l'?quipement Nord - Picardie D?partement Transport Mobilit?s */*Responsable du groupe Syst?mes de Transports*//* */2, rue de Bruxelles, BP 275 59019 Lille cedex FRANCE T?l: +33 (0) 3 20 49 60 70 Fax: +33 (0) 3 20 49 63 69
On Mon, 7 Nov 2011, PALMIER Patrick (Responsable de groupe) - CETE NP/TM/ST wrote:
Thank you for your response, but this is not exactly what I need We are working on a tool that automatically generate R scripts adapted to our surveys databases. When we want to do a table, we select interactively fields, associated labels, functions for an automatic crosstable for example Then, the tool executes R in batch mode with the script produced by the tool The "many scripts" correspond to the many crosstables people want to do. It is not possible produce these different scripts and execute all of them in a unique script with source. For example, people want to do a crosstable, the tool produce a r script that generate the result. Then, the user want to do the same crosstable but on a subset or with different labels. Then, the tools produces another r script, and execute R which reloads at each time all the neeeded packages. Is there a way to avoid this thing and to load packages only once?
You have to load them once per R session. So you could organize your work to use a single session, as Duncan suggested. And that session could wait for input (using something like Rserve). If your packages are taking too long to load, fix the packages. Well-written packages load in milliseconds: after all R itself manages to load several large packages in 100ms or so.
Than you in advance *Patrick PALMIER** *** Le 07/11/2011 15:20, > Duncan Murdoch (par Internet) a ?crit :
On 07/11/2011 5:49 AM, PALMIER Patrick (Responsable de groupe) - CETE NP/TM/ST wrote:
Hello, I use R in batch mode. Each time, I execute a script, R is loading each packages I need in my script. That's Ok But, I had to execute many scripts , and each time R is re-loading the corresponding packages, which take to much time Is it possible ask R to load the packages only once, and stay in memory in background for further scripts, which would avoid to load the packages in each script, or if you have another solution that need to only load packages once in the first scripts, so that further scripts do not need to load these packages too.
Write one script that has a sequence of calls to source() to run the other scripts. You'll need to be careful that unintentional leftover objects and settings from one script don't affect the others; you may also want to use the "echo=TRUE" option when you source, so you see the commands as they are executed. Duncan Murdoch
______________________________________________ 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.
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595