[Rd] Generate .Rout.save files for vignettes
I am looking for a way to generate .Rout.save files for vignettes. The manual Writing R Extensions states here [1] in item number 20: If there is a target output file .Rout.save in the vignette source directory, the output from running the code in that vignette is compared with the target output file. Yet, there is no pointer on how to get the correct .Rout.save files for vignettes. (For the files in directory test there is a footnote on how to get the .Rout.save files. [2]) As a temporary solution, we currently use a script that calls tools:::.run_one_vignette() on each vignette and dumps the output: echo 'tools:::.run_one_vignette(vignette.Rnw, docDir = .);' | R --vanilla vignette.Rout.save However, this doesn't result in the same code as produced by R CMD check. E.g., we get the R startup header and furthermore get the output in German where localization is available (thus having differences when running R CMD check). Does anyone have any hints on how to automatically get the correct results (i.e., without the header)? And is it possible to include these hints in the Writing R extensions manual for other users? Any help is highly appreciated. Best, Benjamin [1] http://cran.r-project.org/doc/manuals/R-exts.html#Checking-packages [2] http://cran.r-project.org/doc/manuals/R-exts.html#fn-15 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Generate .Rout.save files for vignettes
On 12-12-10 11:45 AM, Benjamin Hofner wrote: I am looking for a way to generate .Rout.save files for vignettes. The manual Writing R Extensions states here [1] in item number 20: If there is a target output file .Rout.save in the vignette source directory, the output from running the code in that vignette is compared with the target output file. Yet, there is no pointer on how to get the correct .Rout.save files for vignettes. (For the files in directory test there is a footnote on how to get the .Rout.save files. [2]) I agree, this should be documented. But it is rather easy: Just create an empty file and call it vignette.Rout.save. Run the checks, and you'll get lots of errors because it won't compare to the real output. When you get a compare failure, the file vignette.Rnw.log will be left in the *.Rcheck directory. You can just copy that into the vignette.Rout.save file. Duncan Murdoch As a temporary solution, we currently use a script that calls tools:::.run_one_vignette() on each vignette and dumps the output: echo 'tools:::.run_one_vignette(vignette.Rnw, docDir = .);' | R --vanilla vignette.Rout.save However, this doesn't result in the same code as produced by R CMD check. E.g., we get the R startup header and furthermore get the output in German where localization is available (thus having differences when running R CMD check). Does anyone have any hints on how to automatically get the correct results (i.e., without the header)? And is it possible to include these hints in the Writing R extensions manual for other users? Any help is highly appreciated. Best, Benjamin [1] http://cran.r-project.org/doc/manuals/R-exts.html#Checking-packages [2] http://cran.r-project.org/doc/manuals/R-exts.html#fn-15 __ 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] Generate .Rout.save files for vignettes
But note that this was added at the request of one package author. We don't generally recommended it, not least as people do not take sufficient care about platform differences and keeping such output up to date. So people (including authors) tend to simply ignore a mass of differences. It is better to craft tests with controlled output (and chosen number of significant digits) if you want to check package printed output. On 11/12/2012 13:52, Duncan Murdoch wrote: On 12-12-10 11:45 AM, Benjamin Hofner wrote: I am looking for a way to generate .Rout.save files for vignettes. The manual Writing R Extensions states here [1] in item number 20: If there is a target output file .Rout.save in the vignette source directory, the output from running the code in that vignette is compared with the target output file. Yet, there is no pointer on how to get the correct .Rout.save files for vignettes. (For the files in directory test there is a footnote on how to get the .Rout.save files. [2]) I agree, this should be documented. But it is rather easy: Just create an empty file and call it vignette.Rout.save. Run the checks, and you'll get lots of errors because it won't compare to the real output. When you get a compare failure, the file vignette.Rnw.log will be left in the *.Rcheck directory. You can just copy that into the vignette.Rout.save file. You need to watch out for locale differences: make sure you do this in an English locale for portability (everyone has one of those, the 'C' locale). Duncan Murdoch As a temporary solution, we currently use a script that calls tools:::.run_one_vignette() on each vignette and dumps the output: echo 'tools:::.run_one_vignette(vignette.Rnw, docDir = .);' | R --vanilla vignette.Rout.save However, this doesn't result in the same code as produced by R CMD check. E.g., we get the R startup header and furthermore get the output in German where localization is available (thus having differences when running R CMD check). Does anyone have any hints on how to automatically get the correct results (i.e., without the header)? And is it possible to include these hints in the Writing R extensions manual for other users? Any help is highly appreciated. Best, Benjamin [1] http://cran.r-project.org/doc/manuals/R-exts.html#Checking-packages [2] http://cran.r-project.org/doc/manuals/R-exts.html#fn-15 __ 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 -- Brian D. Ripley, rip...@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, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Catching errors from solve() with near-singular matrices
Dear all, The background is that I'm trying to fix this bug in the geometry package: https://r-forge.r-project.org/tracker/index.php?func=detailaid=1993group_id=1149atid=4552 Boiled down, the problem is that there exists at least one matrix X for which det(X) != 0 and for which solve(X) fails giving the error system is computationally singular: reciprocal condition number = ... (see appended code attached file). I don't want my function that calls solve(X) to return an error. I can think of two strategies for dealing with this problem: Strategy 1: Some code like this: if (det(X) epsilon) { warning(Near singular matrix) return(NULL) } return(solve(X)) The problem is then to find what epsilon should be. Strategy 2: Catch the error thrown by solve(X) like this: f - function(X) { invX - tryCatch(solve(X), error=function(e) { warning(e) error.flag - TRUE}) if (error.flag) return(NULL) return(invX) } This works OK if called without a surrounding try() ret - f(matrix(0, 2, 2)) ## Gives warning However, if I encase the call to f() in a try statement, I get an error: ret1 - try(f(matrix(0, 2, 2))) ## Gives error Lapack routine dgesv: system is exactly singular This is undesirable. Advice on how to solve the problem with either strategy would be much appreciated - as indeed would be a completely different solution. All the best, David. * * * Code to throw an error in solve(): X = as.matrix(read.csv(X.csv)) det(X) [1] 2.32721e-21 solve(X) Error in solve.default(X) : system is computationally singular: reciprocal condition number = 1.79977e-16 -- David C Sterratt, Research Fellow http://homepages.inf.ed.ac.uk/sterratt Institute for Adaptive and Neural Computation tel: +44 131 651 1739 School of Informatics, University of Edinburghfax: +44 131 650 6899 Informatics Forum, 10 Crichton Street, Edinburgh EH8 9AB, Scotland * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * NEW BOOK: Principles of Computational Modelling in Neuroscience Sterratt, Graham, Gillies Willshaw (CUP, 2011). http://www.compneuroprinciples.org The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Catching errors from solve() with near-singular matrices
Dear David, I can think of two strategies for dealing with this problem: Strategy 1: Some code like this: if (det(X) epsilon) { warning(Near singular matrix) return(NULL) } return(solve(X)) This solution is probably the easiest one to take, but to match solve.default, the test should be if (rcond(X) .Machine$double.eps) Catching that case should avoid the error. I hope this helps. All the best, Jon [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Bug in mclapply?
(Sorry for the repeat message; I forgot to send the previous message in plain text.) I've been using mclapply and have encountered situations where it gives errors or returns incorrect results. Here's a minimal example, which gives the error on R 2.15.2 on Mac and Linux: library(parallel) f - function(x) NULL mclapply(1, f, mc.preschedule = FALSE, mc.cores = 1) # Error in sum(sapply(res, inherits, try-error)) : # invalid 'type' (list) of argument I believe it happens when the following are true: - The function returns NULL - mc.preschedule = FALSE - mc.cores = length of the input data Here are some examples I used to trace down the problem. library(parallel) f - function(x) NULL # Error when mc.preschedule=FALSE and mc.cores = length(x) mclapply(1, f, mc.preschedule = FALSE, mc.cores = 1)# Error mclapply(1, f, mc.preschedule = FALSE, mc.cores = 2)# Error mclapply(1:2, f, mc.preschedule = FALSE, mc.cores = 1) # OK # In the following 2 cases, I get an error about 10-20% of the time. # The other times, the result is worse: it returns a list with only one # element, not two! mclapply(1:2, f, mc.preschedule = FALSE, mc.cores = 2) # Error mclapply(1:2, f, mc.preschedule = FALSE, mc.cores = 3) # Error # When mc.preschedule=TRUE, always works mclapply(1, f, mc.preschedule = TRUE, mc.cores = 1)# OK mclapply(1:2, f, mc.preschedule = TRUE, mc.cores = 1) # OK mclapply(1:2, f, mc.preschedule = TRUE, mc.cores = 2) # OK # lapply() always works lapply(1, f)# OK lapply(1:2, f) # OK lapply(1:2, f) # OK # If function returns non-null, it works g - function(x) 0 mclapply(1, g, mc.preschedule = FALSE, mc.cores = 1)# OK mclapply(1:2, g, mc.preschedule = FALSE, mc.cores = 1) # OK mclapply(1:2, g, mc.preschedule = FALSE, mc.cores = 2) # OK Digging around in mclapply(), I think it happens because mccollect(jobs) is returning an empty list. But when I use options(error=recover) and debug the function, I find that when I call mccollect(jobs) again, it returns a list with values -- it's as though mccollect() is returning too early. This will illustrate: mclapply(1, f, mc.preschedule = FALSE, mc.cores = 1) Error in sum(sapply(res, inherits, try-error)) : invalid 'type' (list) of argument Enter a frame number, or 0 to exit 1: mclapply(1, f, mc.preschedule = FALSE, mc.cores = 1) Selection: 1 Called from: top level Browse[1] res named list() Browse[1] res - mccollect(jobs) Browse[1] res $`12348` NULL The error happens on line 63 of mclapply.r, which is after `res - mccollect(jobs)` is called, on line 61. At this point, res should be a named list with values filled in, but it's empty. When I run `res - mccollect(jobs)` again, it gives the correct values. Is there a good way to work around this issue for now? -Winston __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Generate .Rout.save files for vignettes
On 12-12-11 9:41 AM, Prof Brian Ripley wrote: But note that this was added at the request of one package author. We don't generally recommended it, not least as people do not take sufficient care about platform differences and keeping such output up to date. So people (including authors) tend to simply ignore a mass of differences. It is better to craft tests with controlled output (and chosen number of significant digits) if you want to check package printed output. This seems like a useful test for a package developer, but maybe not for package users (or for CRAN, if the developer wants to work in a non-standard locale). I wonder if there's a way to make it easy to use locally, without inconveniencing everyone else? Perhaps it should simply default to not being done, with an environment variable flag set to enable it. Duncan Murdoch On 11/12/2012 13:52, Duncan Murdoch wrote: On 12-12-10 11:45 AM, Benjamin Hofner wrote: I am looking for a way to generate .Rout.save files for vignettes. The manual Writing R Extensions states here [1] in item number 20: If there is a target output file .Rout.save in the vignette source directory, the output from running the code in that vignette is compared with the target output file. Yet, there is no pointer on how to get the correct .Rout.save files for vignettes. (For the files in directory test there is a footnote on how to get the .Rout.save files. [2]) I agree, this should be documented. But it is rather easy: Just create an empty file and call it vignette.Rout.save. Run the checks, and you'll get lots of errors because it won't compare to the real output. When you get a compare failure, the file vignette.Rnw.log will be left in the *.Rcheck directory. You can just copy that into the vignette.Rout.save file. You need to watch out for locale differences: make sure you do this in an English locale for portability (everyone has one of those, the 'C' locale). Duncan Murdoch As a temporary solution, we currently use a script that calls tools:::.run_one_vignette() on each vignette and dumps the output: echo 'tools:::.run_one_vignette(vignette.Rnw, docDir = .);' | R --vanilla vignette.Rout.save However, this doesn't result in the same code as produced by R CMD check. E.g., we get the R startup header and furthermore get the output in German where localization is available (thus having differences when running R CMD check). Does anyone have any hints on how to automatically get the correct results (i.e., without the header)? And is it possible to include these hints in the Writing R extensions manual for other users? Any help is highly appreciated. Best, Benjamin [1] http://cran.r-project.org/doc/manuals/R-exts.html#Checking-packages [2] http://cran.r-project.org/doc/manuals/R-exts.html#fn-15 __ 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 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Generate .Rout.save files for vignettes
On 11/12/2012 17:27, Duncan Murdoch wrote: On 12-12-11 9:41 AM, Prof Brian Ripley wrote: But note that this was added at the request of one package author. We don't generally recommended it, not least as people do not take sufficient care about platform differences and keeping such output up to date. So people (including authors) tend to simply ignore a mass of differences. It is better to craft tests with controlled output (and chosen number of significant digits) if you want to check package printed output. This seems like a useful test for a package developer, but maybe not for package users (or for CRAN, if the developer wants to work in a non-standard locale). I wonder if there's a way to make it easy to use locally, without inconveniencing everyone else? Perhaps it should simply default to not being done, with an environment variable flag set to enable it. What I do (and CRAN recommends for author-mode tests) is to have such a .save file excluded by .Rbuildignore. Duncan Murdoch On 11/12/2012 13:52, Duncan Murdoch wrote: On 12-12-10 11:45 AM, Benjamin Hofner wrote: I am looking for a way to generate .Rout.save files for vignettes. The manual Writing R Extensions states here [1] in item number 20: If there is a target output file .Rout.save in the vignette source directory, the output from running the code in that vignette is compared with the target output file. Yet, there is no pointer on how to get the correct .Rout.save files for vignettes. (For the files in directory test there is a footnote on how to get the .Rout.save files. [2]) I agree, this should be documented. But it is rather easy: Just create an empty file and call it vignette.Rout.save. Run the checks, and you'll get lots of errors because it won't compare to the real output. When you get a compare failure, the file vignette.Rnw.log will be left in the *.Rcheck directory. You can just copy that into the vignette.Rout.save file. You need to watch out for locale differences: make sure you do this in an English locale for portability (everyone has one of those, the 'C' locale). Duncan Murdoch As a temporary solution, we currently use a script that calls tools:::.run_one_vignette() on each vignette and dumps the output: echo 'tools:::.run_one_vignette(vignette.Rnw, docDir = .);' | R --vanilla vignette.Rout.save However, this doesn't result in the same code as produced by R CMD check. E.g., we get the R startup header and furthermore get the output in German where localization is available (thus having differences when running R CMD check). Does anyone have any hints on how to automatically get the correct results (i.e., without the header)? And is it possible to include these hints in the Writing R extensions manual for other users? Any help is highly appreciated. Best, Benjamin [1] http://cran.r-project.org/doc/manuals/R-exts.html#Checking-packages [2] http://cran.r-project.org/doc/manuals/R-exts.html#fn-15 __ 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 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Brian D. Ripley, rip...@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, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] library(tcltk) v. SIGPIPE BUG (?!?)
Hi R-devel, tcltk devel, and sqldf devel, The transcript below shows how loading the tcl/tk library in under R causes subprocesses to ignore SIGPIPE. I am including the developer of the (wonderful) sqldf package since it requires tcltk and you might like to make this dependence optional to the user (at least until this is fixed in tcltk). Am I mistaken in calling this a 'bug'? Any insights appreciated! Thanks, Malcolm Cook Computational Biology - Stowers Institute for Medical Research system(intern=TRUE,'yes | head ') [1] y y y y y y y y y y library(tcltk) Loading Tcl/Tk interface ... done system(intern=TRUE,'yes | head ') ### this now does not return to the prompt and Looking at 'top' shows that 'yes' is running until I hit ctrl-c, after which it returns. C-c C-c [1] y y y y y y y y y y sessionInfo() R version 2.15.1 (2012-06-22) Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) locale: [1] C attached base packages: [1] tcltk stats graphics grDevices utils datasets methods base __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] library(tcltk) v. SIGPIPE BUG (?!?)
On Tue, Dec 11, 2012 at 3:14 PM, Cook, Malcolm m...@stowers.org wrote: Hi R-devel, tcltk devel, and sqldf devel, The transcript below shows how loading the tcl/tk library in under R causes subprocesses to ignore SIGPIPE. I am including the developer of the (wonderful) sqldf package since it requires tcltk and you might like to make this dependence optional to the user (at least until this is fixed in tcltk). Am I mistaken in calling this a 'bug'? Any insights appreciated! Thanks, Malcolm Cook Computational Biology - Stowers Institute for Medical Research system(intern=TRUE,'yes | head ') [1] y y y y y y y y y y library(tcltk) Loading Tcl/Tk interface ... done system(intern=TRUE,'yes | head ') ### this now does not return to the prompt and Looking at 'top' shows that 'yes' is running until I hit ctrl-c, after which it returns. C-c C-c [1] y y y y y y y y y y sessionInfo() R version 2.15.1 (2012-06-22) Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) locale: [1] C attached base packages: [1] tcltk stats graphics grDevices utils datasets methods base As a workaround specify the R engine instead of the tcl engine in wihch case gsubfn (which is called by sqldf) won't try to use the tcltk package: options(gsubfn.engine = R) library(sqldf) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] library(tcltk) v. SIGPIPE BUG (?!?)
Excellent, thanks for the workaround, that gets _me_ by, for now. ~Malcolm -Original Message- From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] Sent: Tuesday, December 11, 2012 2:40 PM To: Cook, Malcolm Cc: r-discuss...@listserv.stowers.org; r-devel@r-project.org; phgrosj...@sciviews.org; Blanchette, Marco Subject: Re: library(tcltk) v. SIGPIPE BUG (?!?) On Tue, Dec 11, 2012 at 3:14 PM, Cook, Malcolm m...@stowers.org wrote: Hi R-devel, tcltk devel, and sqldf devel, The transcript below shows how loading the tcl/tk library in under R causes subprocesses to ignore SIGPIPE. I am including the developer of the (wonderful) sqldf package since it requires tcltk and you might like to make this dependence optional to the user (at least until this is fixed in tcltk). Am I mistaken in calling this a 'bug'? Any insights appreciated! Thanks, Malcolm Cook Computational Biology - Stowers Institute for Medical Research system(intern=TRUE,'yes | head ') [1] y y y y y y y y y y library(tcltk) Loading Tcl/Tk interface ... done system(intern=TRUE,'yes | head ') ### this now does not return to the prompt and Looking at 'top' shows that 'yes' is running until I hit ctrl-c, after which it returns. C-c C-c [1] y y y y y y y y y y sessionInfo() R version 2.15.1 (2012-06-22) Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) locale: [1] C attached base packages: [1] tcltk stats graphics grDevices utils datasets methods base As a workaround specify the R engine instead of the tcl engine in wihch case gsubfn (which is called by sqldf) won't try to use the tcltk package: options(gsubfn.engine = R) library(sqldf) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] library(tcltk) v. SIGPIPE BUG (?!?)
On Dec 11, 2012, at 23:50 , Cook, Malcolm wrote: Excellent, thanks for the workaround, that gets _me_ by, for now. The real issue is probably yet another symptom of something that can be described as insufficient separation between the R engine and its GUI components. Or: One process trying to serve two masters. It is not fixable overnight, but some of us (me, at least) try to find time to get a handle on it. My take is that it is necessary to set things up as separate threads or processes and define the interface via some sort of message-passing protocol. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel