[Rd] possible bug in chron packages
Gavin Simpson
gavin.simpson at ucl.ac.uk
Wed Dec 8 11:59:47 CET 2010
On Wed, 2010-12-08 at 11:26 +0100, Joris Meys wrote:
> Dear,
>
> According to the documentation, the parameters given in "dates" are
> passed to the function "chron". When trying this out, it turns out
> that this apparently doesn't happen, eg:
>
> > dates("20100101",format="Ymd",out.format="day mon year")
> [1] 01/01/10
> > chron("20100101",format="Ymd",out.format="day mon year")
> [1] 01 Jan 2010
It does actually. If you read the code and/or debug `dates` to see what
is happening, `out.format` is passed on to `chron` which does its thing
and passes back the correctly formatted object as specified by
`out.format`.
However, `dates` then goes on to unclass the returned object and then
stick back on a class. It also tries to preserve the "format" in the
first line of `dates`
fmt <- attr(x, "format")
but in your example this is NULL as `x` is just a character. The code
reapplies this stored format later on with
attr(out, "format") <- fmt
as the last line before returning out.
The "format" attribute of the object returned by `chron` never gets
stored or used on the object returned form `dates`.
G
> I would expect the outcome of both functions to be the same, or am I
> overlooking something?
>
> Kind regards
> Joris
>
--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Dr. Gavin Simpson [t] +44 (0)20 7679 0522
ECRC, UCL Geography, [f] +44 (0)20 7679 0565
Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/
UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
More information about the R-devel
mailing list