Re: [Rd] as.Date nuance
This is how strptime() works: it processes the input to match the format. On Fri, 23 Mar 2007, Vladimir Dergachev wrote: > I have encountered a nuance in as.Date() behaviour that is not altogether > obvious - not sure whether this is intended or not: > >> as.Date("2001-01-01error") > [1] "2001-01-01" > > I.e. it ignores the rest of the characters. This happens both in 2.3.1 and > 2.4.1 versions. It has always occurred. > This also happens with explicit format specification: >> as.Date("2006-01-01error", format="%Y-%m-%d") > [1] "2006-01-01" > >thank you > >Vladimir Dergachev -- 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] substitute and S4 objects
Hi all, I don't understand why this does not what I expect : ## code start here ## setClass("num",representation(x="numeric")) num<-function(x) new("num",x=x) add<-function(e1,e2) { cat("Computing ",deparse(substitute(e1)),"+",deparse(substitute(e2)),"\n") [EMAIL PROTECTED]@x } setMethod("+","num",function(e1,e2) { cat("Computing ",deparse(substitute(e1)),"+",deparse(substitute(e2)),"\n") [EMAIL PROTECTED]@x }) a<-num(3.2) b<-num(-1.4) add(a,b) a+b ## code ends here ## a+b does not work : I would like that add(a,b) and a+b give the exact same result I've seen a post on R-devel, but the answer seemed not to apply here. I've tried to use deparse(substitute(e1,sys.frame (-1))) and deparse(substitute(e1,sys.frame(-2))) (as it was advised by GG in january 2006). But it did not work. Therefore, i'm looking for 1) an explanation for this phenomenon (link to a doc, anything) and/or 2) a way to do what i want, if it is possible. Thanks a lot [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] as.Date nuance
On Saturday 24 March 2007 6:21 am, Prof Brian Ripley wrote: > This is how strptime() works: it processes the input to match the format. Except that the format does not match the string - there are leftover characters. Even by R's own definition: > match("a", "ab") [1] NA as, of course, is reasonable. Is there some way to make sure there is an exact match ? thank you ! Vladimir Dergachev > > On Fri, 23 Mar 2007, Vladimir Dergachev wrote: > > I have encountered a nuance in as.Date() behaviour that is not > > altogether > > > > obvious - not sure whether this is intended or not: > >> as.Date("2001-01-01error") > > > > [1] "2001-01-01" > > > > I.e. it ignores the rest of the characters. This happens both in 2.3.1 > > and 2.4.1 versions. > > It has always occurred. > > > This also happens with explicit format specification: > >> as.Date("2006-01-01error", format="%Y-%m-%d") > > > > [1] "2006-01-01" > > > >thank you > > > >Vladimir Dergachev __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] as.Date nuance
It matches in the sense of grep or regexpr grep("a", "ab") > 0 regexpr("a", "ab") > 0 Try this: x <- c("2006-01-01error", "2006-01-01") as.Date(x, "%Y-%m-%d") + ifelse(regexpr("^-..-..$", x) > 0, 0, NA) On 3/24/07, Vladimir Dergachev <[EMAIL PROTECTED]> wrote: > On Saturday 24 March 2007 6:21 am, Prof Brian Ripley wrote: > > This is how strptime() works: it processes the input to match the format. > > Except that the format does not match the string - there are leftover > characters. Even by R's own definition: > > > match("a", "ab") > [1] NA > > as, of course, is reasonable. > > Is there some way to make sure there is an exact match ? > >thank you ! > > Vladimir Dergachev > > > > > On Fri, 23 Mar 2007, Vladimir Dergachev wrote: > > > I have encountered a nuance in as.Date() behaviour that is not > > > altogether > > > > > > obvious - not sure whether this is intended or not: > > >> as.Date("2001-01-01error") > > > > > > [1] "2001-01-01" > > > > > > I.e. it ignores the rest of the characters. This happens both in 2.3.1 > > > and 2.4.1 versions. > > > > It has always occurred. > > > > > This also happens with explicit format specification: > > >> as.Date("2006-01-01error", format="%Y-%m-%d") > > > > > > [1] "2006-01-01" > > > > > >thank you > > > > > >Vladimir Dergachev > > __ > 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
[Rd] Subtle bug in do_basename
Hello, I've been wondering why my no-optimization R-devel builds have been hanging during "building/updating package indices ...". I tracked it down with gdb to this line from do_basename in utils.c: while ( *(p = buf + strlen(buf) - 1) == fsp ) *p = '\0'; Now, imagine if your compiler places the variable fsp immediately before buf on the stack, and strlen(buf) is 0. Yup, you get an infinite loop because p will always be assigned the address of fsp. I'm not quite sure what happens when the stack variables are ordered in a different configuration, probably something bad? Here's a quick fix, but maybe someone would want to find a better one: $ svn diff src/main/util.c Index: src/main/util.c === --- src/main/util.c (revision 40876) +++ src/main/util.c (working copy) @@ -694,7 +694,8 @@ R_fixslash(buf); #endif /* remove trailing file separator(s) */ - while ( *(p = buf + strlen(buf) - 1) == fsp ) *p = '\0'; + if(strlen(p)) + while ( *(p = buf + strlen(buf) - 1) == fsp ) *p = '\0'; if ((p = Rf_strrchr(buf, fsp))) p++; else Best, Jeff -- http://biostat.mc.vanderbilt.edu/JeffreyHorner __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Subtle bug in do_basename
On 3/24/2007 6:02 PM, Jeffrey Horner wrote: > Hello, > > > I've been wondering why my no-optimization R-devel builds have been > hanging during "building/updating package indices ...". I tracked it > down with gdb to this line from do_basename in utils.c: > > while ( *(p = buf + strlen(buf) - 1) == fsp ) *p = '\0'; > > Now, imagine if your compiler places the variable fsp immediately before > buf on the stack, and strlen(buf) is 0. Yup, you get an infinite loop > because p will always be assigned the address of fsp. I'm not quite sure > what happens when the stack variables are ordered in a different > configuration, probably something bad? > > Here's a quick fix, but maybe someone would want to find a better one: I think that looks like the right solution; I'll commit it. Duncan Murdoch > > $ svn diff src/main/util.c > Index: src/main/util.c > === > --- src/main/util.c (revision 40876) > +++ src/main/util.c (working copy) > @@ -694,7 +694,8 @@ > R_fixslash(buf); > #endif > /* remove trailing file separator(s) */ > - while ( *(p = buf + strlen(buf) - 1) == fsp ) *p = '\0'; > + if(strlen(p)) > + while ( *(p = buf + strlen(buf) - 1) == fsp ) *p = '\0'; > if ((p = Rf_strrchr(buf, fsp))) > p++; > else > > Best, > > Jeff __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] substitute and S4 objects
First, by "doesn't work" you mean the printed output. The value returned is the same. Second, the problem is not a general one with S4 methods but with primitive functions. To see this, define a real function with a similar method: > setGeneric("foo", function(e1, e2) standardGeneric("foo")) [1] "foo" > setMethod("foo", "num", function(e1, e2) { cat("Computing\n", deparse(substitute(e1)), "+", deparse(substitute(e2)), "\n") [EMAIL PROTECTED] + e2@ x }) [1] "foo" > foo(a,b) Computing a + b [1] 1.8 The problem with primitives, such as `+`, is that they aren't called in the way functions are normally called. If my understanding is correct, substitute() with one argument uses the "promise" objects corresponding to the formal arguments in order to extract the unevaluated expression. There are no such things with primitives. I think you need to use a different function for whatever you really wanted. Franck Arnaud wrote: > Hi all, > I don't understand why this does not what I expect : > > ## code start here ## > setClass("num",representation(x="numeric")) > > num<-function(x) new("num",x=x) > > add<-function(e1,e2) { > cat("Computing > ",deparse(substitute(e1)),"+",deparse(substitute(e2)),"\n") > [EMAIL PROTECTED]@x > } > > setMethod("+","num",function(e1,e2) { > cat("Computing > ",deparse(substitute(e1)),"+",deparse(substitute(e2)),"\n") > [EMAIL PROTECTED]@x > }) > > > a<-num(3.2) > b<-num(-1.4) > > add(a,b) > a+b > ## code ends here ## > > a+b does not work : I would like that add(a,b) and a+b give the exact same > result > I've seen a post on R-devel, but the answer seemed not to apply here. > I've tried to use deparse(substitute(e1,sys.frame (-1))) and > deparse(substitute(e1,sys.frame(-2))) (as it was advised by GG in january > 2006). But it did not work. > > Therefore, i'm looking for 1) an explanation for this phenomenon (link to a > doc, anything) and/or 2) a way to do what i want, if it is possible. > > Thanks a lot > > [[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