Richard M. Heiberger
2008-Jun-25 04:23 UTC
[R] Incompatible methods ("+.Date", "Ops.difftime") for "+"
I received a warning about incompatible methods that I don't understand. The workaround in this example is simple. What is the reason that these methods are seen as incompatible? Is there some dangerous consequence of my as.numeric() workaround? Can a fix to the code base, perhaps similar to my workaround, make this warning no longer necessary? I am using R 2.7.0 on Windows. version.string R version 2.7.0 (2008-04-22) Thanks Rich xlim <- as.Date(c("2005-04-09", "2007-09-07")) dx <- diff(xlim) xlim + c(-.02, .02)*dx ## correct answer and warning message xlim + as.numeric(c(-.02, .02)*dx) ## correct answer> xlim <- as.Date(c("2005-04-09", "2007-09-07")) > xlim[1] "2005-04-09" "2007-09-07"> dx <- diff(xlim) > dxTime difference of 881 days> xlim + c(-.02, .02)*dx ## correct answer and warning message[1] "2005-03-22" "2007-09-24" Warning message: Incompatible methods ("+.Date", "Ops.difftime") for "+"> xlim + as.numeric(c(-.02, .02)*dx) ## correct answer[1] "2005-03-22" "2007-09-24">
Gabor Grothendieck
2008-Jun-25 05:00 UTC
[R] Incompatible methods ("+.Date", "Ops.difftime") for "+"
You can specify units= to be extra sure: d <- difftime(Sys.Date() + 1, Sys.Date(), units = "mins") as.numeric(d, units = "days") On Wed, Jun 25, 2008 at 12:23 AM, Richard M. Heiberger <rmh at temple.edu> wrote:> I received a warning about incompatible methods that I don't understand. > The workaround in this example is simple. > > What is the reason that these methods are seen as incompatible? > Is there some dangerous consequence of my as.numeric() workaround? > Can a fix to the code base, perhaps similar to my workaround, make this > warning no longer necessary? > > I am using R 2.7.0 on Windows. > version.string R version 2.7.0 (2008-04-22) > > Thanks > > Rich > > > > xlim <- as.Date(c("2005-04-09", "2007-09-07")) > dx <- diff(xlim) > xlim + c(-.02, .02)*dx ## correct answer and warning message > xlim + as.numeric(c(-.02, .02)*dx) ## correct answer > >> xlim <- as.Date(c("2005-04-09", "2007-09-07")) >> xlim > [1] "2005-04-09" "2007-09-07" >> dx <- diff(xlim) >> dx > Time difference of 881 days >> xlim + c(-.02, .02)*dx ## correct answer and warning message > [1] "2005-03-22" "2007-09-24" > Warning message: > Incompatible methods ("+.Date", "Ops.difftime") for "+" >> xlim + as.numeric(c(-.02, .02)*dx) ## correct answer > [1] "2005-03-22" "2007-09-24" >> > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Possibly Parallel Threads
- Incompatible methods ("-.POSIXt", "Ops.difftime") for "-"
- cdplot() with 'POSIXct' x
- multiple plots in same graph window
- In the documentation of 'Ops.Date', please remove mention about "difftime", like in the documentation of 'DateTimeClasses' (PR#14072)
- lattice: index plot