bug in as.data.frame.timeDate with 'anonymous' object

Christopher G. Green (L) cggreen at u.washington.edu
Tue Jun 17 10:09:12 CEST 2008


Greetings,

I think I have stumbled upon a bug in as.data.frame.timeDate in the
fCalendar package. From the unit tests for that package, 

> TC=timeCalendar(2006)
> as.data.frame(TC)
       GMT:TC
1  2006-01-01
2  2006-02-01
3  2006-03-01
4  2006-04-01
5  2006-05-01
6  2006-06-01
7  2006-07-01
8  2006-08-01
9  2006-09-01
10 2006-10-01
11 2006-11-01
12 2006-12-01

which works as expected. But compare this to a call without creating an
intermediate variable:

> as.data.frame(timeCalendar(2006))
Error in names(x) <- value : 
  'names' attribute [2] must be the same length as the vector [1]
> traceback()
4: `colnames<-.default`(`*tmp*`, value = c("GMT:timeCalendar", "GMT:2006"
   ))
3: `colnames<-`(`*tmp*`, value = c("GMT:timeCalendar", "GMT:2006"
   ))
2: as.data.frame.timeDate(timeCalendar(2006))
1: as.data.frame(timeCalendar(2006))


The problem seems to arise from as.data.frame.timeDate's attempt to
construct sensible column names:

> as.data.frame.timeDate
function (x, ...) 
{
    myTZ = Sys.getenv("TZ")
    Sys.setenv(TZ = "GMT")
    stopifnot(inherits(x, "timeDate"))
    ans = as.data.frame.POSIXlt(x at Data, ...)
    colnames(ans) = paste(x at FinCenter, ":", substitute(x), sep = "")
    attr(ans, "control") = c(FinCenter = x at FinCenter)
    Sys.setenv(TZ = myTZ)
    ans
}

Perhaps there could be some default name when substitute(x) returns a vector
of length > 1?


I am using R 2.7.0 on Windows XP SP2. I have fCalendar version 270.75. Let
me know if you need further information. I did not see any posts on this
issue on the R-SIG-Finance list, which is a bit surprising. I a convert from
S-Plus, though, so perhaps I am not looking in the right place.

Chris Green



More information about the Rmetrics-core mailing list