[R-SIG-Finance] plot.xts: Error in parse.format(format[1]) : unrecognized format %b %d%n%H:%M:%S

davidr at rhotrading.com davidr at rhotrading.com
Wed Dec 10 22:59:21 CET 2008


Sorry, Jeff, but it doesn't work for me.
(Gabor's workaround does, though.)

> plot(xts(rnorm(10),as.chron(Sys.time())+1:10),
major.format=c(dates='m-d-y',times='h:m:s'))
Error in parse.format(format[1]) : unrecognized format %b %d%n%Y

I also tried major.format=NULL to no avail.

I guess I can use the workaround for now.

Thanks to Jeff and Gabor!
-- David


-----Original Message-----
From: Jeff Ryan [mailto:jeff.a.ryan at gmail.com] 
Sent: Wednesday, December 10, 2008 3:14 PM
To: David Reiner <davidr at rhotrading.com>
Cc: r-sig-finance at stat.math.ethz.ch
Subject: Re: [R-SIG-Finance] plot.xts: Error in parse.format(format[1])
: unrecognized format %b %d%n%H:%M:%S

David,

Forgot to add you can also just set major.format=NULL to get the
default chron formating

Jeff

On Wed, Dec 10, 2008 at 3:12 PM, Jeff Ryan <jeff.a.ryan at gmail.com>
wrote:
> Hi David,
>
> The strangeness comes from chron:
> ?format.chron
>
>  format: vector or list specifying the input format of the input. The
>          format can be either strings specifying one of the recognized
>          formats below or a list of user-supplied functions to convert
>          dates from character into Julian dates and vice versa.
>
>          The dates format can be any permutation of the characters
>          '"d"', '"m"', or '"y"' delimited by a separator (possibly
>          null), e.g., '"m/d/y"', '"d-m-y"', '"ymd"', are all valid;
>          the format can also be permutations of the words '"day"',
>          '"month"' and '"year"' (with non-null separator), which
>          produces the month name, e.g., '"month day year"' produces
>          '"April 20 1992"', '"day mon year"' produces '"20 Apr 1992"'.
>
>          The times format can be any permutation of '"h"', '"m"', and
>          '"s"' separated by any one non-special character.  The
>          default is '"h:m:s"'.
>
>> format(as.chron(Sys.time())+1:10, format=c(dates="m-d-y",times="h"))
> Error in parse.format(format.) : unrecognized format h
>> format(as.chron(Sys.time())+1:10,
format=c(dates="m-d-y",times="h:m:s"))
>  [1] "(12-11-08 21:08:12)" "(12-12-08 21:08:12)" "(12-13-08 21:08:12)"
>  [4] "(12-14-08 21:08:12)" "(12-15-08 21:08:12)" "(12-16-08 21:08:12)"
>  [7] "(12-17-08 21:08:12)" "(12-18-08 21:08:12)" "(12-19-08 21:08:12)"
> [10] "(12-20-08 21:08:12)"
>
> so for plot.xts the default is causing issues (as it tries to
> automatically format for visual usefulness).
>
> Try:
>
> plot(xts(rnorm(10),as.chron(Sys.time())+1:10),
> major.format=c(dates='m-d-y',times='h:m:s'))
>
> I'll add a test in plot.xts to handle this formatting convention if it
> is a chron object.
>
> HTH
> Jeff
> On Wed, Dec 10, 2008 at 2:57 PM,  <davidr at rhotrading.com> wrote:
>> I cannot figure out what's wrong here.
>> If someone could shed some light, I'd appreciate it very much.
>>
>>
>> I form an xts object with a chron index (small version here) that
seems
>> OK, but I can't plot it:
>>
>>> plot(gesmall)
>> Error in parse.format(format[1]) : unrecognized format %b
%d%n%H:%M:%S
>>
>>> str(gesmall)
>> An 'xts' object from (12/07/08 19:46:40) to (12/07/08 19:46:50)
>> containing:
>>  Data: num [1:11, 1] 98 98 98 98 98 ...
>>  - attr(*, "dimnames")=List of 2
>>  ..$ : NULL
>>  ..$ : NULL
>>  Indexed by: Classes 'chron', 'dates', 'times'  atomic [1:11] 14221
>> 14221 14221 14221 14221 ...
>>  ..- attr(*, "format")= Named chr [1:2] "m/d/y" "h:m:s"
>>  .. ..- attr(*, "names")= chr [1:2] "dates" "times"
>>  ..- attr(*, "origin")= Named num [1:3] 1 1 1970
>>  .. ..- attr(*, "names")= chr [1:3] "month" "day" "year"
>>  xts Attributes:
>>  NULL
>>
>>> summary(gesmall)
>>     Index                        gesmall
>>  Min.   :(12/07/08 19:46:40)   Min.   :98.04
>>  1st Qu.:(12/07/08 19:46:42)   1st Qu.:98.04
>>  Median :(12/07/08 19:46:45)   Median :98.04
>>  Mean   :(12/07/08 19:46:45)   Mean   :98.04
>>  3rd Qu.:(12/07/08 19:46:48)   3rd Qu.:98.04
>>  Max.   :(12/07/08 19:46:50)   Max.   :98.04
>>
>>> gesmall
>>
>> (12/07/08 19:46:40) 98.04
>> (12/07/08 19:46:41) 98.04
>> (12/07/08 19:46:42) 98.04
>> (12/07/08 19:46:43) 98.04
>> (12/07/08 19:46:44) 98.04
>> (12/07/08 19:46:45) 98.04
>> (12/07/08 19:46:46) 98.04
>> (12/07/08 19:46:47) 98.04
>> (12/07/08 19:46:48) 98.04
>> (12/07/08 19:46:49) 98.04
>> (12/07/08 19:46:50) 98.04
>>
>>> # It looks as if there are somehow empty field names; not sure how
>> that happens or if it's important
>>
>>> sessionInfo()
>> R version 2.8.0 Patched (2008-11-02 r46817)
>> i386-pc-mingw32
>>
>> locale:
>> LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
>> States.1252;LC_MONETARY=English_United
>> States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
>>
>> attached base packages:
>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>
>>
>> other attached packages:
>> [1] xts_0.0-16   zoo_1.5-4    chron_2.3-24
>>
>> loaded via a namespace (and not attached):
>> [1] grid_2.8.0      lattice_0.17-15 tools_2.8.0
>>
>> Thanks,
>> -- David
>>
>> _______________________________________________
>> R-SIG-Finance at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only.
>> -- If you want to post, subscribe first.
>>
>
>
>
> --
> Jeffrey Ryan
> jeffrey.ryan at insightalgo.com
>
> ia: insight algorithmics
> www.insightalgo.com
>



-- 
Jeffrey Ryan
jeffrey.ryan at insightalgo.com

ia: insight algorithmics
www.insightalgo.com



More information about the R-SIG-Finance mailing list