Re: FW: [R] is.weekend() odd behaviour
I think the user should be forced to convert explicitly from POSIXct to chron before is.weekend is used. That way the user will know for sure what time zone he is converting with respect to. Having it done silently will just cause subtle errors. IMHO the correct functionality is to give an error message if the user attempts to provide a POSIXct date. Matthew Dowle concordiafunds.com> writes: : : Kurt, : : Uwe suggested I write to you as maintainer of chron ... at the start of : is.weekend, in the check on the argument type, maybe just change chron() to : as.chron()? This would ensure as.chron.POSIXt gets called on POSIXt : arguments, and (I think) fixes the problem. I tested and it seems ok. No : warning/error required. : : > is.weekend : function(x) : { : if(!inherits(x, "dates")) : if(is.character(x) || is.numeric(x)) : x <- as.chron(x) # was x <- chron(x) : else stop("x must inherit from dates") : : } : : -Original Message- : From: Uwe Ligges [mailto:ligges statistik.uni-dortmund.de] : Sent: 26 May 2004 13:20 : To: Matthew Dowle : Cc: 'r-help stat.math.ethz.ch' : Subject: Re: [R] is.weekend() odd behaviour : : : Matthew Dowle wrote: : : > Thanks. When is.weekend() is given an object it doesn't know about, : > could a warning or error be added? At the moment, I think you're : > agreeing, that it silently returns a random TRUE/FALSE. : : It's not random, it depends on the value of Sys.time(), which also : includes seconds . : I agree that a warning or error might be sensible. So I think you are : about to write a note to the maintainer of package "chron" including : patches for is.weekend() and friends? : : Uwe Ligges : : : > -Original Message- : > From: Uwe Ligges [mailto:ligges statistik.uni-dortmund.de] : > Sent: 26 May 2004 11:55 : > To: Matthew Dowle : > Cc: 'r-help stat.math.ethz.ch' : > Subject: Re: [R] is.weekend() odd behaviour : > : > : > Matthew Dowle wrote: : > : > : >>It seems is.weekend() is unsure ? : > : > : > It is completely sure, if an object is given is.weekend() knows about : > as in: : > : > table(is.weekend(sapply(1:100, : > function(i){Sys.sleep(0.05);as.chron(Sys.time())}))) : > : > (note the as.chron() call!) : > : > Uwe Ligges : > : > : > : > : >># Start R 1.9.0 with --vanilla on windows xp : >># load package chron : >> : >> : >> : >>>table(is.weekend(sapply(1:100, : >>>function(i){Sys.sleep(0.05);Sys.time()}))) : >> : >>FALSE TRUE : >> 6832 : >> : >> : >>>date() : >> : >>[1] "Wed May 26 11:18:56 2004" : >> : >> : >> : >>>version _ : >> : >>platform i386-pc-mingw32 : >>arch i386 : >>os mingw32 : >>system i386, mingw32 : >>status : >>major1 : >>minor9.0 : >>year 2004 : >>month04 : >>day 12 : >>language R __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
FW: [R] is.weekend() odd behaviour
Kurt, Uwe suggested I write to you as maintainer of chron ... at the start of is.weekend, in the check on the argument type, maybe just change chron() to as.chron()? This would ensure as.chron.POSIXt gets called on POSIXt arguments, and (I think) fixes the problem. I tested and it seems ok. No warning/error required. > is.weekend function(x) { if(!inherits(x, "dates")) if(is.character(x) || is.numeric(x)) x <- as.chron(x) # was x <- chron(x) else stop("x must inherit from dates") } -Original Message- From: Uwe Ligges [mailto:[EMAIL PROTECTED] Sent: 26 May 2004 13:20 To: Matthew Dowle Cc: '[EMAIL PROTECTED]' Subject: Re: [R] is.weekend() odd behaviour Matthew Dowle wrote: > Thanks. When is.weekend() is given an object it doesn't know about, > could a warning or error be added? At the moment, I think you're > agreeing, that it silently returns a random TRUE/FALSE. It's not random, it depends on the value of Sys.time(), which also includes seconds . I agree that a warning or error might be sensible. So I think you are about to write a note to the maintainer of package "chron" including patches for is.weekend() and friends? Uwe Ligges > -Original Message- > From: Uwe Ligges [mailto:[EMAIL PROTECTED] > Sent: 26 May 2004 11:55 > To: Matthew Dowle > Cc: '[EMAIL PROTECTED]' > Subject: Re: [R] is.weekend() odd behaviour > > > Matthew Dowle wrote: > > >>It seems is.weekend() is unsure ? > > > It is completely sure, if an object is given is.weekend() knows about > as in: > > table(is.weekend(sapply(1:100, > function(i){Sys.sleep(0.05);as.chron(Sys.time())}))) > > (note the as.chron() call!) > > Uwe Ligges > > > > >># Start R 1.9.0 with --vanilla on windows xp >># load package chron >> >> >> >>>table(is.weekend(sapply(1:100, >>>function(i){Sys.sleep(0.05);Sys.time()}))) >> >>FALSE TRUE >> 6832 >> >> >>>date() >> >>[1] "Wed May 26 11:18:56 2004" >> >> >> >>>version _ >> >>platform i386-pc-mingw32 >>arch i386 >>os mingw32 >>system i386, mingw32 >>status >>major1 >>minor9.0 >>year 2004 >>month04 >>day 12 >>language R >> >> >> >> [[alternative HTML version deleted]] >> >>__ >>[EMAIL PROTECTED] mailing list >>https://www.stat.math.ethz.ch/mailman/listinfo/r-help >>PLEASE do read the posting guide! >>http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] is.weekend() odd behaviour
Uwe Ligges statistik.uni-dortmund.de> writes: > Matthew Dowle wrote: > > > >>table(is.weekend(sapply(1:100, function(i){Sys.sleep(0.05);Sys.time()}))) > > > > FALSE TRUE > >6832 > > > It seems is.weekend() is unsure ? > > It is completely sure, if an object is given is.weekend() knows about as in: > > table(is.weekend(sapply(1:100, > function(i){Sys.sleep(0.05);as.chron(Sys.time())}))) > > (note the as.chron() call!) Note that converting a POSIXct to chron using as.chron uses the GMT datetime, not the datetime in your timezone. So if its the weekend in the GMT timezone but not in yours it will indicate that its the weekend. Similarly if its the weekend in your timezone but not in the GMT timezone then it will indicate its not in the weekend. If you want the result relative to your timezone convert to chron like this: now <- Sys.time() chron(unclass(as.Date(format(now or even easier: chron(unclass(Sys.Date())) Now apply is.weekend to that. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] is.weekend() odd behaviour
Matthew Dowle wrote: Thanks. When is.weekend() is given an object it doesn't know about, could a warning or error be added? At the moment, I think you're agreeing, that it silently returns a random TRUE/FALSE. It's not random, it depends on the value of Sys.time(), which also includes seconds . I agree that a warning or error might be sensible. So I think you are about to write a note to the maintainer of package "chron" including patches for is.weekend() and friends? Uwe Ligges -Original Message- From: Uwe Ligges [mailto:[EMAIL PROTECTED] Sent: 26 May 2004 11:55 To: Matthew Dowle Cc: '[EMAIL PROTECTED]' Subject: Re: [R] is.weekend() odd behaviour Matthew Dowle wrote: It seems is.weekend() is unsure ? It is completely sure, if an object is given is.weekend() knows about as in: table(is.weekend(sapply(1:100, function(i){Sys.sleep(0.05);as.chron(Sys.time())}))) (note the as.chron() call!) Uwe Ligges # Start R 1.9.0 with --vanilla on windows xp # load package chron table(is.weekend(sapply(1:100, function(i){Sys.sleep(0.05);Sys.time()}))) FALSE TRUE 6832 date() [1] "Wed May 26 11:18:56 2004" version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major1 minor9.0 year 2004 month04 day 12 language R [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] is.weekend() odd behaviour
Thanks. When is.weekend() is given an object it doesn't know about, could a warning or error be added? At the moment, I think you're agreeing, that it silently returns a random TRUE/FALSE. -Original Message- From: Uwe Ligges [mailto:[EMAIL PROTECTED] Sent: 26 May 2004 11:55 To: Matthew Dowle Cc: '[EMAIL PROTECTED]' Subject: Re: [R] is.weekend() odd behaviour Matthew Dowle wrote: > It seems is.weekend() is unsure ? It is completely sure, if an object is given is.weekend() knows about as in: table(is.weekend(sapply(1:100, function(i){Sys.sleep(0.05);as.chron(Sys.time())}))) (note the as.chron() call!) Uwe Ligges > # Start R 1.9.0 with --vanilla on windows xp > # load package chron > > >>table(is.weekend(sapply(1:100, >>function(i){Sys.sleep(0.05);Sys.time()}))) > > FALSE TRUE >6832 > >>date() > > [1] "Wed May 26 11:18:56 2004" > > >>version _ > > platform i386-pc-mingw32 > arch i386 > os mingw32 > system i386, mingw32 > status > major1 > minor9.0 > year 2004 > month04 > day 12 > language R > > > > [[alternative HTML version deleted]] > > __ > [EMAIL PROTECTED] mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] is.weekend() odd behaviour
Matthew Dowle wrote: It seems is.weekend() is unsure ? It is completely sure, if an object is given is.weekend() knows about as in: table(is.weekend(sapply(1:100, function(i){Sys.sleep(0.05);as.chron(Sys.time())}))) (note the as.chron() call!) Uwe Ligges # Start R 1.9.0 with --vanilla on windows xp # load package chron table(is.weekend(sapply(1:100, function(i){Sys.sleep(0.05);Sys.time()}))) FALSE TRUE 6832 date() [1] "Wed May 26 11:18:56 2004" version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major1 minor9.0 year 2004 month04 day 12 language R [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] is.weekend() odd behaviour
It seems is.weekend() is unsure ? # Start R 1.9.0 with --vanilla on windows xp # load package chron > table(is.weekend(sapply(1:100, function(i){Sys.sleep(0.05);Sys.time()}))) FALSE TRUE 6832 > date() [1] "Wed May 26 11:18:56 2004" > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major1 minor9.0 year 2004 month04 day 12 language R > [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html