Re: [Rd] Speed-up/Cache loadNamespace()
It's possible to run R (or a c parent process) as a background process via a named pipe, and then write script files to the named pipe. However, the details depend on what shell you use. The last time I tried (which was a long time ago), I created a small c program to run R, read from the named pipe from within c, then wrote it's contents to R's standard in. It might be possible to do it without the c program. Haven't checked. On Mon, Jul 20, 2020 at 3:50 AM Mario Annau wrote: > > Dear all, > > in our current setting we have our packages stored on a (rather slow) > network drive and need to invoke short R scripts (using RScript) in a > timely manner. Most of the script's runtime is spent with package loading > using library() (or loadNamespace to be precise). > > Is there a way to cache the package namespaces as listed in > loadedNamespaces() and load them into memory before the script is executed? > > My first simplistic attempt was to serialize the environment output > from loadNamespace() to a file and load it before the script is started. > However, loading the object automatically also loads all the referenced > namespaces (from the slow network share) which is undesirable for this use > case. > > Cheers, > Mario > > [[alternative HTML version deleted]] > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Speed-up/Cache loadNamespace()
On Mon, Jul 20, 2020 at 9:15 AM Abby Spurdle wrote: > > It's possible to run R (or a c parent process) as a background process > via a named pipe, and then write script files to the named pipe. > However, the details depend on what shell you use. I would use screen or tmux for this, if this is an R process that you want to interact with, and you want to keep it running after a SIGHUP. Gabor [...] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Speed-up/Cache loadNamespace()
Le 20/07/2020 à 10:15, Abby Spurdle a écrit : It's possible to run R (or a c parent process) as a background process via a named pipe, and then write script files to the named pipe. However, the details depend on what shell you use. The last time I tried (which was a long time ago), I created a small c program to run R, read from the named pipe from within c, then wrote it's contents to R's standard in. It might be possible to do it without the c program. Haven't checked. For testing purposes, you can do: - in a shell 1: mkfifo rpipe exec 3>rpipe # without this trick, Rscript will end after the first "echo" hereafter or at the end of your first script. - in a shell 2: Rscript rfifo - in a shell 3: echo "print('hello')" > rpipe echo "print('hello again')" > rpipe Then in the shell 2, you will see the output: [1] "hello" [1] "hello again" etc. If your R scripts contain "stop()" or "q('yes')" or any other error, it will end the Rscript process. Kind of watch-dog can be set for automatic relaunching if needed. Another way to stop the Rscript process is to kill the "exec 3>rpipe" one. You can find its PID with "fuser rpipe" Best, Serguei. On Mon, Jul 20, 2020 at 3:50 AM Mario Annau wrote: Dear all, in our current setting we have our packages stored on a (rather slow) network drive and need to invoke short R scripts (using RScript) in a timely manner. Most of the script's runtime is spent with package loading using library() (or loadNamespace to be precise). Is there a way to cache the package namespaces as listed in loadedNamespaces() and load them into memory before the script is executed? My first simplistic attempt was to serialize the environment output from loadNamespace() to a file and load it before the script is started. However, loading the object automatically also loads all the referenced namespaces (from the slow network share) which is undesirable for this use case. Cheers, Mario [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Serguei Sokol Ingenieur de recherche INRAE Cellule mathématiques TBI, INSA/INRAE UMR 792, INSA/CNRS UMR 5504 135 Avenue de Rangueil 31077 Toulouse Cedex 04 tel: +33 5 61 55 98 49 email: so...@insa-toulouse.fr http://www.toulouse-biotechnology-institute.fr/ __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Methods for objects inheriting from lme (nlme package)
Dear R developers, One function in my mkin package [1] returns an object that is originally created by nlme(), but contains some additional information. Its class is c("mmkin.nlme", "nlme", "lme"). Now I would like to use the anova() method for lme objects for comparing such S3 objects. Unfortunately, anova.lme currently does not check for inheritance, but checks the first element of the class attribute (as obtained by data.class()) against a hardcoded list of classes in order to decide if it will work or not. Therefore, I created a bug report [2], containing a patch [3] for nlme that makes anova.lme check for inheritance. Encouraged by a kind comment by Elin Waring in the BTS, I have now revisited my bug report, and discovered that the help page for data.class() claims that its return value (the first element of the class attribute vector) is "what is typically useful for method dispatching". However, I think that this use case illustrates that it would be useful not only to check for the primary class, but rather for class inheritance. Do you agree that it is preferable for the S3 method to check for inheritance instead of checking against a hardcoded list in this case? Kind regards, Johannes Ranke [1] https://github.com/jranke/mkin/blob/master/R/nlme.mmkin.R [2] https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17761 [3] https://bugs.r-project.org/bugzilla/attachment.cgi?id=2578 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Methods for objects inheriting from lme (nlme package)
Am Montag, 20. Juli 2020, 11:12:25 CEST schrieb Johannes Ranke: > Dear R developers, > > One function in my mkin package [1] returns an object that is originally > created by nlme(), but contains some additional information. Its class is > c("mmkin.nlme", "nlme", "lme"). > > Now I would like to use the anova() method for lme objects for comparing > such S3 objects. Unfortunately, anova.lme currently does not check for > inheritance, but checks the first element of the class attribute (as > obtained by data.class()) against a hardcoded list of classes in order to > decide if it will work or not. > > Therefore, I created a bug report [2], containing a patch [3] for nlme that > makes anova.lme check for inheritance. > > Encouraged by a kind comment by Elin Waring in the BTS, I have now revisited > my bug report, and discovered that the help page for data.class() claims > that its return value (the first element of the class attribute vector) is > "what is typically useful for method dispatching". > > However, I think that this use case illustrates that it would be useful not > only to check for the primary class, but rather for class inheritance. > > Do you agree that it is preferable for the S3 method to check for > inheritance instead of checking against a hardcoded list in this case? > > Kind regards, > > Johannes Ranke > > > [1] https://github.com/jranke/mkin/blob/master/R/nlme.mmkin.R > [2] https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17761 > [3] https://bugs.r-project.org/bugzilla/attachment.cgi?id=2578 P.S.: I have updated the patch [4] based on comments provided by Sebastian Meyer. [4] https://bugs.r-project.org/bugzilla/attachment.cgi?id=2656 [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Speed-up/Cache loadNamespace()
Thank you Serguei and Gabor. Great suggestions. > If your R scripts contain "stop()" or "q('yes')" or any other error, it > will end the Rscript process. Kind of watch-dog can be set for automatic > relaunching if needed. It should be possible to change the error handling behavior. >From within R: options (error = function () NULL) Or something better... Also, it may be desirable to wipe the global environment (or parts of it), after each script: remove (list = ls (envir=.GlobalEnv, all.names=TRUE) ) __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Speed-up/Cache loadNamespace()
Mario, Abby, et al. Note that there is no fully safe way of unloading packages which register methods (as answered by Luke Tierney here: https://bugs.r-project.org/bugzilla/show_bug.cgi?id=16644 ) which makes the single R session running arbitrary different scripts thing pretty iffy over the long term. Even swtichr (which tries hard to support something based on this) only gets "pretty close". If the scripts are always the same (up to bugfixes, etc) and most importantly require the same loaded packages then the above won't be an issue, of course. Just something to be aware of when planning something like this. Best, ~G On Mon, Jul 20, 2020 at 2:59 PM Abby Spurdle wrote: > Thank you Serguei and Gabor. > Great suggestions. > > > If your R scripts contain "stop()" or "q('yes')" or any other error, it > > will end the Rscript process. Kind of watch-dog can be set for automatic > > relaunching if needed. > > It should be possible to change the error handling behavior. > From within R: > > options (error = function () NULL) > > Or something better... > > Also, it may be desirable to wipe the global environment (or parts of > it), after each script: > > remove (list = ls (envir=.GlobalEnv, all.names=TRUE) ) > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] trivial typo in ?Matrix::sparse.model.matrix.Rd
"form" -> "from". Diff against latest SVN: Index: sparse.model.matrix.Rd === --- sparse.model.matrix.Rd (revision 3336) +++ sparse.model.matrix.Rd (working copy) @@ -4,7 +4,7 @@ \alias{fac2sparse} \alias{fac2Sparse} \description{Construct a sparse model or \dQuote{design} matrix, - form a formula and data frame (\code{sparse.model.matrix}) or a single + from a formula and data frame (\code{sparse.model.matrix}) or a single factor (\code{fac2sparse}). The \code{fac2[Ss]parse()} functions are utilities, also used __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel