[Rd] as.function()
Hi [this after some considerable thought as to R-help vs R-devel] I want to write a (S3) method for as.function(); toy example follows. Given a matrix a, I need to evaluate trace(ax) as a function of (matrix) x. Here's a trace function: tr - function (a) { i - seq_len(nrow(a)) return(sum(a[cbind(i, i)])) } How do I accomplish the following: a - crossprod(matrix(rnorm(12),ncol=3)) class(a) - foo f - as.function(a) # need help to write as.function.foo() x - diag(3) f(x) #should give tr(ax) a - 4 f(x) # should still give tr(ax) even though a has been reassigned. [my real example is very much more complicated than this but I need this toy one too and I can't see how to modify as.function.polynomial() to do what I want] -- Robin Hankin Uncertainty Analyst and Neutral Theorist, National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] as.function()
Try this: as.function.foo - function(obj, ...) { newobj - function(x, ...){} body(newobj) - obj return(newobj) } x - expression(2*x + 3*x^2) foo - as.function.foo(x) foo(2) Hope this help On 14/01/2008, Robin Hankin [EMAIL PROTECTED] wrote: Antonio thanks for your help here, but it doesn't answer my question. Perhaps if I outline my motivation it would help. I want to recreate the ability of the polynom package to do the following: library(polynom) p - polynomial(1:4) p 1 + 2*x + 3*x^2 + 4*x^3 MySpecialFunction - as.function(p) MySpecialFunction(1:10) [1] 10 49 142 313 586 985 1534 2257 3178 4321 p - 4 MySpecialFunction(1:10) [1] 10 49 142 313 586 985 1534 2257 3178 4321 See how the user can define object MySpecialFunction, which outlives short-lived polynomial p. Unfortunately, I don't see a way to modify as.function.polynomial() to do what I want. best wishes rksh On 14 Jan 2008, at 08:45, Antonio, Fabio Di Narzo wrote: 2008/1/14, Robin Hankin [EMAIL PROTECTED]: Hi [this after some considerable thought as to R-help vs R-devel] I want to write a (S3) method for as.function(); toy example follows. Given a matrix a, I need to evaluate trace(ax) as a function of (matrix) x. Here's a trace function: tr - function (a) { i - seq_len(nrow(a)) return(sum(a[cbind(i, i)])) } How do I accomplish the following: a - crossprod(matrix(rnorm(12),ncol=3)) class(a) - foo f - as.function(a) # need help to write as.function.foo() x - diag(3) f(x) #should give tr(ax) What about the following? as.function.foo - function(a, ...) function(x) sum(diag(a*x)) However, I don't see the need for an S3 method. Why don't simply use (?): mulTraceFun - function(a) function(x) sum(diag(a*x)) So you also have a more meaningful name than an anonymous 'as.function'. HTH, Antonio. a - 4 f(x) # should still give tr(ax) even though a has been reassigned. This would'nt work with my proposal, because of lexical scoping. [my real example is very much more complicated than this but I need this toy one too and I can't see how to modify as.function.polynomial() to do what I want] -- Robin Hankin Uncertainty Analyst and Neutral Theorist, National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Antonio, Fabio Di Narzo Ph.D. student at Department of Statistical Sciences University of Bologna, Italy -- Robin Hankin Uncertainty Analyst and Neutral Theorist, National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] as.function()
On Mon, 14 Jan 2008, Henrique Dallazuanna wrote: Try this: as.function.foo - function(obj, ...) { newobj - function(x, ...){} body(newobj) - obj return(newobj) } x - expression(2*x + 3*x^2) foo - as.function.foo(x) foo(2) Well, that copies what as.function.polynomial did but that was written for S3 well before R was started. Here you can use environments: as.function.foo - function(obj, ...) function(x, ...) eval(obj) Hope this help On 14/01/2008, Robin Hankin [EMAIL PROTECTED] wrote: Antonio thanks for your help here, but it doesn't answer my question. Perhaps if I outline my motivation it would help. I want to recreate the ability of the polynom package to do the following: library(polynom) p - polynomial(1:4) p 1 + 2*x + 3*x^2 + 4*x^3 MySpecialFunction - as.function(p) MySpecialFunction(1:10) [1] 10 49 142 313 586 985 1534 2257 3178 4321 p - 4 MySpecialFunction(1:10) [1] 10 49 142 313 586 985 1534 2257 3178 4321 See how the user can define object MySpecialFunction, which outlives short-lived polynomial p. Unfortunately, I don't see a way to modify as.function.polynomial() to do what I want. best wishes rksh On 14 Jan 2008, at 08:45, Antonio, Fabio Di Narzo wrote: 2008/1/14, Robin Hankin [EMAIL PROTECTED]: Hi [this after some considerable thought as to R-help vs R-devel] I want to write a (S3) method for as.function(); toy example follows. Given a matrix a, I need to evaluate trace(ax) as a function of (matrix) x. Here's a trace function: tr - function (a) { i - seq_len(nrow(a)) return(sum(a[cbind(i, i)])) } How do I accomplish the following: a - crossprod(matrix(rnorm(12),ncol=3)) class(a) - foo f - as.function(a) # need help to write as.function.foo() x - diag(3) f(x) #should give tr(ax) What about the following? as.function.foo - function(a, ...) function(x) sum(diag(a*x)) However, I don't see the need for an S3 method. Why don't simply use (?): mulTraceFun - function(a) function(x) sum(diag(a*x)) So you also have a more meaningful name than an anonymous 'as.function'. HTH, Antonio. a - 4 f(x) # should still give tr(ax) even though a has been reassigned. This would'nt work with my proposal, because of lexical scoping. [my real example is very much more complicated than this but I need this toy one too and I can't see how to modify as.function.polynomial() to do what I want] -- Robin Hankin Uncertainty Analyst and Neutral Theorist, National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Antonio, Fabio Di Narzo Ph.D. student at Department of Statistical Sciences University of Bologna, Italy -- Robin Hankin Uncertainty Analyst and Neutral Theorist, National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Brian D. Ripley, [EMAIL PROTECTED] 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] knnFinder package
Dear all, I have found some serious bugs in the knnFinder package (which supports data structures and algorithms for both exact and approximate nearest neighbor searching in arbitrarily high dimensions) that may trigger segmentation faults. I have fixed them but I had troubles to contact its maintainer Samuel E. Kemp (previously with the University of Glamorgan, UK). Do someone know where I can reach him ? Best regards, Greg --- Gregoire Pau EMBL/EBI Cambridge, UK http://www.ebi.ac.uk/~gpau __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Possible bug in R 2.6.1 (PR#10565)
Colleagues, =20 In using the paste command I have to spell out the collapse option: =20 paste(1:3,coll=3Da) [1] 1 a 2 a 3 a paste(1:3,collapse=3Da) [1] 1a2a3 =20 My understanding is that the abbreviation coll should be adequate. Actually, even collaps isn't enough: =20 paste(1:3,collaps=3Da) [1] 1 a 2 a 3 a =20 LG =20 Lionel Galway, Ph.D. Senior Statistician The RAND Corporation voice: (+1) 310-393-0411 x7957 1776 Main St. fax:(+1) 310-393-4818 Santa Monica, CA 90407 USA email: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]=20 =20 =20 __ This email message is for the sole use of the intended r...{{dropped:3}} __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Possible bug in R 2.6.1 (PR#10565)
On Fri, 11 Jan 2008, [EMAIL PROTECTED] wrote: Colleagues, =20 In using the paste command I have to spell out the collapse option: =20 paste(1:3,coll=3Da) [1] 1 a 2 a 3 a paste(1:3,collapse=3Da) [1] 1a2a3 =20 My understanding is that the abbreviation coll should be adequate. Actually, even collaps isn't enough: Your understanding is wrong. The help page says Usage: paste(..., sep = , collapse = NULL) Argument names after ... cannot be abbreviated ('S Programming' p.40, amongst other places). I do often wonder why people are 'sure you know for certain' (to quote the FAQ) that something as elementary as this would be a bug for so many years. It indicates a lack of respect for the R developers. =20 paste(1:3,collaps=3Da) [1] 1 a 2 a 3 a =20 LG =20 Lionel Galway, Ph.D. Senior Statistician The RAND Corporation voice: (+1) 310-393-0411 x7957 1776 Main St. fax:(+1) 310-393-4818 Santa Monica, CA 90407 USA email: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED]=20 -- Brian D. Ripley, [EMAIL PROTECTED] 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
Re: [Rd] as.function()
Robin Hankin wrote: Hi [this after some considerable thought as to R-help vs R-devel] I want to write a (S3) method for as.function(); toy example follows. Given a matrix a, I need to evaluate trace(ax) as a function of (matrix) x. Here's a trace function: tr - function (a) { i - seq_len(nrow(a)) return(sum(a[cbind(i, i)])) } How do I accomplish the following: a - crossprod(matrix(rnorm(12),ncol=3)) class(a) - foo f - as.function(a) # need help to write as.function.foo() x - diag(3) f(x) #should give tr(ax) a - 4 f(x) # should still give tr(ax) even though a has been reassigned. Brian's answer was what you want. A less general version is this: as.function.foo - function(x, ...) { +function(b) tr(x %*% b) + } (I switched the names of the args, because the first arg to as.function.foo should match the name of the first arg to as.function). I was a little surprised that this worked even if a was changed without ever evaluating f, because I thought lazy evaluation would mess up that case. But of course the value of x is forced when R evaluates it to find out the class for dispatch to the method. Duncan Murdoch __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] as.function()
On 14 Jan 2008, at 10:57, Prof Brian Ripley wrote: On Mon, 14 Jan 2008, Henrique Dallazuanna wrote: Try this: as.function.foo - function(obj, ...) { newobj - function(x, ...){} body(newobj) - obj return(newobj) } x - expression(2*x + 3*x^2) foo - as.function.foo(x) foo(2) Well, that copies what as.function.polynomial did but that was written for S3 well before R was started. Here you can use environments: as.function.foo - function(obj, ...) function(x, ...) eval(obj) Yes, did is the operative word here.The new as.function.polynomial() is considerably slicker and more general. But both old and new versions 'unpick' the polynomial x into its elements and create a function, line by line, that depends on the elements of x. The new version uses: as.function.polynomial - function (x, ...) { clever and efficient creation of list ex as a function of vector x snipped f - function(x) NULL body(f) - ex f } The old version uses: as.function.polynomial - function (x, ...) { clever and efficient creation of character string jj as a function of vector x snipped f - function(x) NULL body(f) - parse(text = jj )[[1]] f } If f - as.function.foo(x), somehow the f object has to include within itself the entirety of x. In my case, x is [of course] an arbitrary- dimensional array of possibly complex elements. So I can't use Bill/Kurt's method (at least not easily) because my object is considerably more complicated than a vector. And I don't have an example that works on a complicated object to copy. Hope this help On 14/01/2008, Robin Hankin [EMAIL PROTECTED] wrote: Antonio thanks for your help here, but it doesn't answer my question. Perhaps if I outline my motivation it would help. I want to recreate the ability of the polynom package to do the following: library(polynom) p - polynomial(1:4) p 1 + 2*x + 3*x^2 + 4*x^3 MySpecialFunction - as.function(p) MySpecialFunction(1:10) [1] 10 49 142 313 586 985 1534 2257 3178 4321 p - 4 MySpecialFunction(1:10) [1] 10 49 142 313 586 985 1534 2257 3178 4321 See how the user can define object MySpecialFunction, which outlives short-lived polynomial p. Unfortunately, I don't see a way to modify as.function.polynomial() to do what I want. best wishes rksh -- Robin Hankin Uncertainty Analyst and Neutral Theorist, National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] as.function()
On 14 Jan 2008, at 11:50, Duncan Murdoch wrote: Robin Hankin wrote: Hi [snip] a - crossprod(matrix(rnorm(12),ncol=3)) class(a) - foo f - as.function(a) # need help to write as.function.foo() x - diag(3) f(x) #should give tr(ax) a - 4 f(x) # should still give tr(ax) even though a has been reassigned. Brian's answer was what you want. A less general version is this: as.function.foo - function(x, ...) { +function(b) tr(x %*% b) + } Wow. Got it! Looks like I'll have to read the R Language Definition again. Thanks everyone. (I switched the names of the args, because the first arg to as.function.foo should match the name of the first arg to as.function). I was a little surprised that this worked even if a was changed without ever evaluating f, because I thought lazy evaluation would mess up that case. But of course the value of x is forced when R evaluates it to find out the class for dispatch to the method. Duncan Murdoch -- Robin Hankin Uncertainty Analyst and Neutral Theorist, National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] as.function()
On Mon, 14 Jan 2008, Duncan Murdoch wrote: Robin Hankin wrote: Hi [this after some considerable thought as to R-help vs R-devel] I want to write a (S3) method for as.function(); toy example follows. Given a matrix a, I need to evaluate trace(ax) as a function of (matrix) x. Here's a trace function: tr - function (a) { i - seq_len(nrow(a)) return(sum(a[cbind(i, i)])) } How do I accomplish the following: a - crossprod(matrix(rnorm(12),ncol=3)) class(a) - foo f - as.function(a) # need help to write as.function.foo() x - diag(3) f(x) #should give tr(ax) a - 4 f(x) # should still give tr(ax) even though a has been reassigned. Brian's answer was what you want. A less general version is this: as.function.foo - function(x, ...) { +function(b) tr(x %*% b) + } And see the R version of as.function.polynomial called Rpoly in 'S Programming' p.95 for a similar example, in case yet another is needed (and to set the record straight after RH's unthinking reply). (I switched the names of the args, because the first arg to as.function.foo should match the name of the first arg to as.function). I was a little surprised that this worked even if a was changed without ever evaluating f, because I thought lazy evaluation would mess up that case. But of course the value of x is forced when R evaluates it to find out the class for dispatch to the method. Duncan Murdoch -- Brian D. Ripley, [EMAIL PROTECTED] 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
Re: [Rd] knnFinder package
On Mon, 14 Jan 2008, Gregoire Pau wrote: Dear all, I have found some serious bugs in the knnFinder package (which supports data structures and algorithms for both exact and approximate nearest neighbor searching in arbitrarily high dimensions) that may trigger segmentation faults. I have fixed them but I had troubles to contact its maintainer Samuel E. Kemp (previously with the University of Glamorgan, UK). Do someone know where I can reach him ? I have also tried, for the same reason, without result. He seems to have been a student who has now left the university where he wrote the package. I also wrote to his apparent supervisor, also without result. My suggestion would be that the package be orphaned, and that if you are willing to replace it with your version, and to adopt it as maintainer, its posting on CRAN can be continued. Roger Best regards, Greg --- Gregoire Pau EMBL/EBI Cambridge, UK http://www.ebi.ac.uk/~gpau __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: [EMAIL PROTECTED] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Possible bug in R 2.6.1 (PR#10565)
[Brian Ripley] I do often wonder why people are 'sure you know for certain' (to quote the FAQ) that something as elementary as this would be a bug for so many years. It indicates a lack of respect for the R developers. Not at all. A bug report may be naive, or even wrong, and still be driven by good will, and be rightly interpreted as an attempt at a contribution to both the R community and R developers. The lack of respect only exists in the head of susceptible developers. Some of them are nevertheless admirable for their expertise, commitment and contributions. The truth is that, deep down, _nobody_ is perfect. Tolerance and kindness usually are more fruitful attitudes, not only on the R lists, but everywhere. -- François Pinard http://pinard.progiciels-bpi.ca __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Possible bug in R 2.6.1 (PR#10565)
On Mon, 14 Jan 2008, [iso-8859-1] François Pinard wrote: [Brian Ripley] I do often wonder why people are 'sure you know for certain' (to quote the FAQ) that something as elementary as this would be a bug for so many years. It indicates a lack of respect for the R developers. Not at all. A bug report may be naive, or even wrong, and still be driven by good will, and be rightly interpreted as an attempt at a contribution to both the R community and R developers. Brian's point is that there is an *explicit* request (in both the posting guide and the FAQ) not to send things to R-bugs unless you are *sure* they are bugs. Queries about *possible* bugs are welcome on r-devel or r-help as appropriate. Someone who sends a query about a possible bug to r-bugs has either not read the posting guide or has chosen to ignore the request. It is possible that the request in the posting guide is not sufficiently clear and they just misunderstand it, but I haven't seen anyone claim this. If that's what you mean, then suggestions for making it clearer would be considered. If someone presents code on r-help or r-devel that produces behaviour they don't understand and asks if it is bug (rather than asserting that it must be a bug) they have a much higher chance of receiving a friendly reply [and an even higher chance of receiving a helpful reply] -thomas Thomas Lumley Assoc. Professor, Biostatistics [EMAIL PROTECTED] University of Washington, Seattle __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] as.function()
On Jan 14, 2008 6:50 AM, Duncan Murdoch [EMAIL PROTECTED] wrote: Robin Hankin wrote: Hi [this after some considerable thought as to R-help vs R-devel] I want to write a (S3) method for as.function(); toy example follows. Given a matrix a, I need to evaluate trace(ax) as a function of (matrix) x. Here's a trace function: tr - function (a) { i - seq_len(nrow(a)) return(sum(a[cbind(i, i)])) } How do I accomplish the following: a - crossprod(matrix(rnorm(12),ncol=3)) class(a) - foo f - as.function(a) # need help to write as.function.foo() x - diag(3) f(x) #should give tr(ax) a - 4 f(x) # should still give tr(ax) even though a has been reassigned. Brian's answer was what you want. A less general version is this: as.function.foo - function(x, ...) { +function(b) tr(x %*% b) + } This can also be done using the proto package. p has two components b and f. q inherits f from p but has its own b. library(proto) p - proto(b = 1:4, f = function(., x) sum(diag(x %*% .$b))) q - p$proto(b = 5:8) p$f(1:4) q$f(1:4) __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] %s in filename when opening device causes crash (PR#10571)
Full_Name: Richard Cotton Version: 2.6.1 OS: Windows XP (32bit) Submission from: (NULL) (193.119.236.82) Using %s in a filename when opening a device causes R to crash, e.g., pdf(foo%s.pdf) win.metafile(foo%s.wmf) postscript(foo%s.ps) __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] %s in filename when opening device causes crash (PR#10571)
On Mon, 14 Jan 2008, [EMAIL PROTECTED] wrote: Full_Name: Richard Cotton Version: 2.6.1 OS: Windows XP (32bit) Submission from: (NULL) (193.119.236.82) Using %s in a filename when opening a device causes R to crash, e.g., pdf(foo%s.pdf) win.metafile(foo%s.wmf) postscript(foo%s.ps) Do you have a workaround for this? Since that is done at C level, we can't easily trap this (especially on Windows), and the list of possible errors that might cause a crash is rather long. It has been considered as a vulnerability, but there seems no simple solution. -- Brian D. Ripley, [EMAIL PROTECTED] 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
Re: [Rd] %s in filename when opening device causes crash (PR#10571)
Same on 2.7.0 Under development (unstable) (2007-12-21 r43753) using Ubuntu i686 2.6.22-14-generic: * ~: R :: R version 2.7.0 Under development (unstable) (2007-12-21 r43753) pdf pdf(foo%s.pdf) *** caught segfault *** address 0x1, cause 'memory not mapped' Traceback: 1: .External(PDF, file, old$paper, old$family, old$encoding, old$bg, old$fg, old$width, old$height, old$pointsize, onefile, old$pagecentre, old$title, old$fonts, version[1], version[2]) 2: pdf(foo%s.pdf) Possible actions: 1: abort (with core dump, if enabled) 2: normal R exit 3: exit R without saving workspace 4: exit R saving workspace Selection: 2 * ~: [EMAIL PROTECTED] wrote: Full_Name: Richard Cotton Version: 2.6.1 OS: Windows XP (32bit) Submission from: (NULL) (193.119.236.82) Using %s in a filename when opening a device causes R to crash, e.g., pdf(foo%s.pdf) win.metafile(foo%s.wmf) postscript(foo%s.ps) __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Dr Oleg Sklyar * EBI-EMBL, Cambridge CB10 1SD, UK * +44-1223-494466 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Possible bug in R 2.6.1 (PR#10565)
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Thomas Lumley Sent: Monday, January 14, 2008 11:24 AM To: François Pinard Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: [Rd] Possible bug in R 2.6.1 (PR#10565) On Mon, 14 Jan 2008, [iso-8859-1] François Pinard wrote: [Brian Ripley] I do often wonder why people are 'sure you know for certain' (to quote the FAQ) that something as elementary as this would be a bug for so many years. It indicates a lack of respect for the R developers. Not at all. A bug report may be naive, or even wrong, and still be driven by good will, and be rightly interpreted as an attempt at a contribution to both the R community and R developers. Brian's point is ... and François Pinard's is that you should (sic) be more tolerant and forgiving to _your_ users. BTW, my standing ovations to François Pinard excellent language and wordings. I wish I could do it as well :-( Thanks for understanding, Latchezar Dimitrov that there is an *explicit* request (in both the posting guide and the FAQ) not to send things to R-bugs unless you are *sure* they are bugs. Queries about *possible* bugs are welcome on r-devel or r-help as appropriate. Someone who sends a query about a possible bug to r-bugs has either not read the posting guide or has chosen to ignore the request. It is possible that the request in the posting guide is not sufficiently clear and they just misunderstand it, but I haven't seen anyone claim this. If that's what you mean, then suggestions for making it clearer would be considered. If someone presents code on r-help or r-devel that produces behaviour they don't understand and asks if it is bug (rather than asserting that it must be a bug) they have a much higher chance of receiving a friendly reply [and an even higher chance of receiving a helpful reply] -thomas Thomas Lumley Assoc. Professor, Biostatistics [EMAIL PROTECTED] University of Washington, Seattle __ 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] as.function()
How about this as a version that automatically constructs the argument list (and make into a method for as.function as appropriate)? makefun - function(expr) { f - function() {} body(f) - expr vars - all.vars(expr) if (length(vars)) { args - alist(x=)[rep(1,length(vars))] names(args) - vars formals(f) - args } environment(f) - globalenv() return(f) } makefun(expression(2*x + 3*y^2)) function (x, y) 2 * x + 3 * y^2 makefun(expression(2*x + 3*y^2 - z)) function (x, y, z) 2 * x + 3 * y^2 - z makefun(expression(p1 + p2)) function (p1, p2) p1 + p2 -- Tony Plate Henrique Dallazuanna wrote: Try this: as.function.foo - function(obj, ...) { newobj - function(x, ...){} body(newobj) - obj return(newobj) } x - expression(2*x + 3*x^2) foo - as.function.foo(x) foo(2) Hope this help On 14/01/2008, Robin Hankin [EMAIL PROTECTED] wrote: Antonio thanks for your help here, but it doesn't answer my question. Perhaps if I outline my motivation it would help. I want to recreate the ability of the polynom package to do the following: library(polynom) p - polynomial(1:4) p 1 + 2*x + 3*x^2 + 4*x^3 MySpecialFunction - as.function(p) MySpecialFunction(1:10) [1] 10 49 142 313 586 985 1534 2257 3178 4321 p - 4 MySpecialFunction(1:10) [1] 10 49 142 313 586 985 1534 2257 3178 4321 See how the user can define object MySpecialFunction, which outlives short-lived polynomial p. Unfortunately, I don't see a way to modify as.function.polynomial() to do what I want. best wishes rksh On 14 Jan 2008, at 08:45, Antonio, Fabio Di Narzo wrote: 2008/1/14, Robin Hankin [EMAIL PROTECTED]: Hi [this after some considerable thought as to R-help vs R-devel] I want to write a (S3) method for as.function(); toy example follows. Given a matrix a, I need to evaluate trace(ax) as a function of (matrix) x. Here's a trace function: tr - function (a) { i - seq_len(nrow(a)) return(sum(a[cbind(i, i)])) } How do I accomplish the following: a - crossprod(matrix(rnorm(12),ncol=3)) class(a) - foo f - as.function(a) # need help to write as.function.foo() x - diag(3) f(x) #should give tr(ax) What about the following? as.function.foo - function(a, ...) function(x) sum(diag(a*x)) However, I don't see the need for an S3 method. Why don't simply use (?): mulTraceFun - function(a) function(x) sum(diag(a*x)) So you also have a more meaningful name than an anonymous 'as.function'. HTH, Antonio. a - 4 f(x) # should still give tr(ax) even though a has been reassigned. This would'nt work with my proposal, because of lexical scoping. [my real example is very much more complicated than this but I need this toy one too and I can't see how to modify as.function.polynomial() to do what I want] -- Robin Hankin Uncertainty Analyst and Neutral Theorist, National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Antonio, Fabio Di Narzo Ph.D. student at Department of Statistical Sciences University of Bologna, Italy -- Robin Hankin Uncertainty Analyst and Neutral Theorist, National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 __ 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] as.function()
The gsubfn package can do something like that too. If you preface a function with fn$ then it will interpret certain formula arguments as functions. If all we want is the function itself we can use force, the identity function, to recover it: library(gsubfn) fn$force(~ 2*x + 3*y^2) function (x, y) 2 * x + 3 * y^2 If there are free variables in the formula that you don't want to include in the argument list the left hand side can be used to specify the argument list: fn$force(x + y ~ 2*x + a*y^2) function (x, y) 2 * x + a * y^2 On Jan 14, 2008 1:05 PM, Tony Plate [EMAIL PROTECTED] wrote: How about this as a version that automatically constructs the argument list (and make into a method for as.function as appropriate)? makefun - function(expr) { f - function() {} body(f) - expr vars - all.vars(expr) if (length(vars)) { args - alist(x=)[rep(1,length(vars))] names(args) - vars formals(f) - args } environment(f) - globalenv() return(f) } makefun(expression(2*x + 3*y^2)) function (x, y) 2 * x + 3 * y^2 makefun(expression(2*x + 3*y^2 - z)) function (x, y, z) 2 * x + 3 * y^2 - z makefun(expression(p1 + p2)) function (p1, p2) p1 + p2 -- Tony Plate Henrique Dallazuanna wrote: Try this: as.function.foo - function(obj, ...) { newobj - function(x, ...){} body(newobj) - obj return(newobj) } x - expression(2*x + 3*x^2) foo - as.function.foo(x) foo(2) Hope this help On 14/01/2008, Robin Hankin [EMAIL PROTECTED] wrote: Antonio thanks for your help here, but it doesn't answer my question. Perhaps if I outline my motivation it would help. I want to recreate the ability of the polynom package to do the following: library(polynom) p - polynomial(1:4) p 1 + 2*x + 3*x^2 + 4*x^3 MySpecialFunction - as.function(p) MySpecialFunction(1:10) [1] 10 49 142 313 586 985 1534 2257 3178 4321 p - 4 MySpecialFunction(1:10) [1] 10 49 142 313 586 985 1534 2257 3178 4321 See how the user can define object MySpecialFunction, which outlives short-lived polynomial p. Unfortunately, I don't see a way to modify as.function.polynomial() to do what I want. best wishes rksh On 14 Jan 2008, at 08:45, Antonio, Fabio Di Narzo wrote: 2008/1/14, Robin Hankin [EMAIL PROTECTED]: Hi [this after some considerable thought as to R-help vs R-devel] I want to write a (S3) method for as.function(); toy example follows. Given a matrix a, I need to evaluate trace(ax) as a function of (matrix) x. Here's a trace function: tr - function (a) { i - seq_len(nrow(a)) return(sum(a[cbind(i, i)])) } How do I accomplish the following: a - crossprod(matrix(rnorm(12),ncol=3)) class(a) - foo f - as.function(a) # need help to write as.function.foo() x - diag(3) f(x) #should give tr(ax) What about the following? as.function.foo - function(a, ...) function(x) sum(diag(a*x)) However, I don't see the need for an S3 method. Why don't simply use (?): mulTraceFun - function(a) function(x) sum(diag(a*x)) So you also have a more meaningful name than an anonymous 'as.function'. HTH, Antonio. a - 4 f(x) # should still give tr(ax) even though a has been reassigned. This would'nt work with my proposal, because of lexical scoping. [my real example is very much more complicated than this but I need this toy one too and I can't see how to modify as.function.polynomial() to do what I want] -- Robin Hankin Uncertainty Analyst and Neutral Theorist, National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Antonio, Fabio Di Narzo Ph.D. student at Department of Statistical Sciences University of Bologna, Italy -- Robin Hankin Uncertainty Analyst and Neutral Theorist, National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 __ 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] %s in filename when opening device causes crash (PR#10571)
[EMAIL PROTECTED] wrote: On Mon, 14 Jan 2008, [EMAIL PROTECTED] wrote: Full_Name: Richard Cotton Version: 2.6.1 OS: Windows XP (32bit) Submission from: (NULL) (193.119.236.82) Using %s in a filename when opening a device causes R to crash, e.g., pdf(foo%s.pdf) win.metafile(foo%s.wmf) postscript(foo%s.ps) Do you have a workaround for this? Since that is done at C level, we can't easily trap this (especially on Windows), and the list of possible errors that might cause a crash is rather long. It has been considered as a vulnerability, but there seems no simple solution. Yes. The problem is of course that we do want a sprintf() format there for Rplot%03d.pdf et al. One option would be to escape % except when in (regexp) %[0-9]*d, which seems nontrivial, but not impossible. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] %s in filename when opening device causes crash (PR#10571)
On Mon, 14 Jan 2008, Peter Dalgaard wrote: [EMAIL PROTECTED] wrote: On Mon, 14 Jan 2008, [EMAIL PROTECTED] wrote: Full_Name: Richard Cotton Version: 2.6.1 OS: Windows XP (32bit) Submission from: (NULL) (193.119.236.82) Using %s in a filename when opening a device causes R to crash, e.g., pdf(foo%s.pdf) win.metafile(foo%s.wmf) postscript(foo%s.ps) Do you have a workaround for this? Since that is done at C level, we can't easily trap this (especially on Windows), and the list of possible errors that might cause a crash is rather long. It has been considered as a vulnerability, but there seems no simple solution. Yes. The problem is of course that we do want a sprintf() format there for Rplot%03d.pdf et al. One option would be to escape % except when in (regexp) %[0-9]*d, which seems nontrivial, but not impossible. But there are other integer formats (%i, %u, %x, %X), and other flags (# might be useful). So the list of valid inputs is also rather long. It would be tedious to do at C level, but a check in the R-level wrapper would be easier (if not 'simple'). BTW, this occurs in other places, e.g. the title argument of quartz() and, from R-devel, X11(). -- Brian D. Ripley, [EMAIL PROTECTED] 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] illegal data frame produced by [-.data.frame (PR#10574)
x - data.frame(a=1:3,b=2:4) x[,3] - x Warning message: In `[-.data.frame`(`*tmp*`, , 3, value = list(a = 1:3, b = 2:4)) : provided 2 variables to replace 1 variables x a b a.1 b.1 1 1 2 1 NULL 2 2 3 2 NA 3 3 4 3 NA Warning message: In format.data.frame(x, digits = digits, na.encode = FALSE) : corrupt data frame: columns will be truncated or padded with NAs In S-PLUS, the first warning is given, then a legal data frame is produced, using only the first column of value. The following change to R's [-.data.frame gives that behavior. Change: else if (ncolv p) warning(gettextf(provided %d variables to replace %d variables, ncolv, p), domain = NA) to: else if (ncolv p) { warning(gettextf(provided %d variables to replace %d variables, ncolv, p), domain = NA) new.cols - new.cols[seq_len(p)] } --please do not edit the information below-- Version: platform = i386-pc-mingw32 arch = i386 os = mingw32 system = i386, mingw32 status = major = 2 minor = 6.1 year = 2007 month = 11 day = 26 svn rev = 43537 language = R version.string = R version 2.6.1 (2007-11-26) Windows XP (build 2600) Service Pack 2.0 Locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 Search Path: .GlobalEnv, package:stats, package:graphics, package:grDevices, package:utils, package:datasets, package:methods, Autoloads, package:base __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] extra space in: all.equal(5,6) (PR#10575)
all.equal(5,6) [1] Mean relative difference: 0.2 Note the odd extra space. A fix is to change lines in all.equal.numeric from: if (is.na(xy) || xy tolerance) msg - c(msg, paste(Mean, what, if (cplx) Mod, difference:, format(xy))) to: if (cplx) what - paste(what, Mod) if (is.na(xy) || xy tolerance) msg - c(msg, paste(Mean, what, difference:, format(xy))) --please do not edit the information below-- Version: platform = i386-pc-mingw32 arch = i386 os = mingw32 system = i386, mingw32 status = major = 2 minor = 6.1 year = 2007 month = 11 day = 26 svn rev = 43537 language = R version.string = R version 2.6.1 (2007-11-26) Windows XP (build 2600) Service Pack 2.0 Locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 Search Path: .GlobalEnv, package:stats, package:graphics, package:grDevices, package:utils, package:datasets, package:methods, Autoloads, package:base __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] rm: failed to get attributes of `/':
Recently I have heard reports like the one below a couple of times: Tineke Casneuf wrote: However I did encouter an error when trying to install a self-made dummy package. I am sure it is not due to the package because it can be build on someone else's windows PC. The error message is *rm: failed to get attributes of `/': No such file or directory. Today I saw one live, and managed to track down the problem. Cygwin (from which the Windows R toolset gets a number of utilities), stores information on its mounts in the Windows registry. If you later uninstall it but leave the registry entries in place, you'll get an error like the above. The rm utility thinks that / refers to a directory like c:\cygwin, but such a directory doesn't exist. I don't know if this is a bug in the Cygwin uninstaller (which I would say should remove registry entries once they are no longer valid), in rm (which should ignore mounts that don't make sense), or if it is user error. But the fix is quite simple: look in the registry (under HKEY_CURRENT_USER\Software\Cygnus Solutions\Cygwin\mounts v2, or the same location in HKEY_LOCAL_MACHINE), and remove any invalid mounts. I will modify the Rtools installer to work around this problem. Duncan Murdoch __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Rscript argument processing minor bug with -g
On 5 January 2008 at 19:34, Dan Davison wrote: | I think there's a minor bug in the argument-processing carried out by Rscript. | The effect is that if one passes -g as a flag to the script, it is erroneously | exposed to the main executable's argument processing and therefore generates a | message about not being able to comply with the request for a particular GUI. | Uppercase G is fine as are the other 25 letters in upper or lower case. | | I noticed this with R-2.5.1 and carried out the tests below with R-devel-2.7.0. [...] | ~/src/scripts/R /usr/src/R/R-devel/bin/Rscript -e commandArgs() -a -b -f -g -h | WARNING: unknown gui '-h', using X11 | | [1] /usr/src/R/R-devel/bin/exec/R --slave | [3] --no-restore -e | [5] commandArgs() --args | [7] -a-b | [9] -f-g | [11] -h For what it's worth, littler does not have that problem with Following GNU traditions, we stick all arguments that are not referring to existing switches into the argv vector which you can access normally: [EMAIL PROTECTED]:~ r -e 'print(argv)' -- -a -b -f -g -h -i -j [1] -a -b -f -g -h -i -j It is then up to you to parse these remaining arguments. If you hit an existing option like -h _before_ the --, its code gets invoked. This also works when code is piped into littler (when '-' is used to turn on stdin parsing): [EMAIL PROTECTED]:~ echo 'print(argv)' | r - -- -a -b -f -g -h -i -j [1] -a -b -f -g -h -i -j Prior versions had an off-by-one error in the way argv was built, but version 0.1.0 which I just put onto http://dirk.eddelbuettel.com/code/littler.html should be fine. Hope this helps, Dirk -- Three out of two people have difficulties with fractions. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel