Re: [Rd] bug with strptime, %OS, and "."

2017-01-12 Thread frederik
Thanks for the reply. That's a creative way to do it, but I wanted to
use the same format string for both parsing and formatting my file
name.

I figured I should just put this on the bug tracker in case someone is
editing strptime at some point in the distant future:

https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=17208

I also made a related bug asking for e.g. "%OS6" to be accepted by
strptime.

https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=17209

Cheers,

Frederick

On Wed, Jan 11, 2017 at 01:36:07PM +, Upton, Stephen (Steve) (CIV) wrote:
> Works for me:
> > strptime("17_35_14.01234.mp3","%H_%M_%OS")$sec
> [1] 14.01234
> > strptime("17_35_14.mp3","%H_%M_%OS")$sec
> [1] 14
> 
> Just leave off the ".mp3" in your time pattern.
> 
> Relevant section from the help ("Details") for strptime:
> strptime converts character vectors to class "POSIXlt": its input x is first
> converted by as.character. Each input string is processed as far as
> necessary for the format specified: any trailing characters are ignored.
> 
> R version 3.3.2 (2016-10-31)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
> Running under: Windows 7 x64 (build 7601) Service Pack 1
> 
> Stephen C. Upton
> Faculty Associate - Research
> SEED (Simulation Experiments & Efficient Designs) Center
> Operations Research Department
> Naval Postgraduate School
> Mobile: 804-994-4257
> NIPR: scup...@nps.edu
> SIPR: upto...@nps.navy.smil.mil
> SEED Center web site: http://harvest.nps.edu
> -Original Message-
> From: R-devel [mailto:r-devel-boun...@r-project.org] On Behalf Of
> frede...@ofb.net
> Sent: Tuesday, January 10, 2017 9:59 PM
> To: Dirk Eddelbuettel
> Cc: R-devel
> Subject: Re: [Rd] bug with strptime, %OS, and "."
> 
> On Tue, Jan 10, 2017 at 08:13:21PM -0600, Dirk Eddelbuettel wrote:
> > 
> > On 10 January 2017 at 17:48, frede...@ofb.net wrote:
> > | Hi R Devel,
> > | 
> > | I just ran into a corner case with 'strptime'. Recall that the "%OS"
> > | conversion accepts fractional seconds:
> > | 
> > | > strptime("17_35_14.01234.mp3","%H_%M_%OS.mp3")$sec
> > | [1] 14.01234
> > | 
> > | Unfortunately for my application it seems to be "greedy", in that it 
> > | tries to parse a decimal point which might belong to the rest of the
> > | format:
> > | 
> > | > strptime("17_35_14.mp3","%H_%M_%OS.mp3")
> > | [1] NA
> > 
> > Maybe just don't use the optional O:
> > 
> >R> strptime("17_35_14.mp3","%H_%M_%S.mp3")$sec
> >[1] 14
> >R> 
> >R> strptime("17_35_14.mp3","%H_%M_%S.mp3")
> >[1] "2017-01-10 17:35:14 CST"
> >R>
> 
> For my application I wanted to be able to accept both formats, "14.mp3" and
> "14.01234.mp3". Since "14" and "14.01234" both parse as numbers, I thought
> "%OS" should accept both.
> 
> Yes, I can work around it fairly easily.
> 
> Frederick
> 
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] bug with strptime, %OS, and "."

2017-01-11 Thread Upton, Stephen (Steve) (CIV)
Works for me:
> strptime("17_35_14.01234.mp3","%H_%M_%OS")$sec
[1] 14.01234
> strptime("17_35_14.mp3","%H_%M_%OS")$sec
[1] 14

Just leave off the ".mp3" in your time pattern.

Relevant section from the help ("Details") for strptime:
strptime converts character vectors to class "POSIXlt": its input x is first
converted by as.character. Each input string is processed as far as
necessary for the format specified: any trailing characters are ignored.

R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Stephen C. Upton
Faculty Associate - Research
SEED (Simulation Experiments & Efficient Designs) Center
Operations Research Department
Naval Postgraduate School
Mobile: 804-994-4257
NIPR: scup...@nps.edu
SIPR: upto...@nps.navy.smil.mil
SEED Center web site: http://harvest.nps.edu
-Original Message-
From: R-devel [mailto:r-devel-boun...@r-project.org] On Behalf Of
frede...@ofb.net
Sent: Tuesday, January 10, 2017 9:59 PM
To: Dirk Eddelbuettel
Cc: R-devel
Subject: Re: [Rd] bug with strptime, %OS, and "."

On Tue, Jan 10, 2017 at 08:13:21PM -0600, Dirk Eddelbuettel wrote:
> 
> On 10 January 2017 at 17:48, frede...@ofb.net wrote:
> | Hi R Devel,
> | 
> | I just ran into a corner case with 'strptime'. Recall that the "%OS"
> | conversion accepts fractional seconds:
> | 
> | > strptime("17_35_14.01234.mp3","%H_%M_%OS.mp3")$sec
> | [1] 14.01234
> | 
> | Unfortunately for my application it seems to be "greedy", in that it 
> | tries to parse a decimal point which might belong to the rest of the
> | format:
> | 
> | > strptime("17_35_14.mp3","%H_%M_%OS.mp3")
> | [1] NA
> 
> Maybe just don't use the optional O:
> 
>R> strptime("17_35_14.mp3","%H_%M_%S.mp3")$sec
>[1] 14
>R> 
>R> strptime("17_35_14.mp3","%H_%M_%S.mp3")
>[1] "2017-01-10 17:35:14 CST"
>R>

For my application I wanted to be able to accept both formats, "14.mp3" and
"14.01234.mp3". Since "14" and "14.01234" both parse as numbers, I thought
"%OS" should accept both.

Yes, I can work around it fairly easily.

Frederick

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] bug with strptime, %OS, and "."

2017-01-10 Thread frederik
On Tue, Jan 10, 2017 at 08:13:21PM -0600, Dirk Eddelbuettel wrote:
> 
> On 10 January 2017 at 17:48, frede...@ofb.net wrote:
> | Hi R Devel,
> | 
> | I just ran into a corner case with 'strptime'. Recall that the "%OS"
> | conversion accepts fractional seconds:
> | 
> | > strptime("17_35_14.01234.mp3","%H_%M_%OS.mp3")$sec
> | [1] 14.01234
> | 
> | Unfortunately for my application it seems to be "greedy", in that it
> | tries to parse a decimal point which might belong to the rest of the
> | format:
> | 
> | > strptime("17_35_14.mp3","%H_%M_%OS.mp3")
> | [1] NA
> 
> Maybe just don't use the optional O:
> 
>R> strptime("17_35_14.mp3","%H_%M_%S.mp3")$sec
>[1] 14
>R> 
>R> strptime("17_35_14.mp3","%H_%M_%S.mp3")
>[1] "2017-01-10 17:35:14 CST"
>R>

For my application I wanted to be able to accept both formats,
"14.mp3" and "14.01234.mp3". Since "14" and "14.01234" both parse as
numbers, I thought "%OS" should accept both.

Yes, I can work around it fairly easily.

Frederick

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] bug with strptime, %OS, and "."

2017-01-10 Thread Dirk Eddelbuettel

On 10 January 2017 at 17:48, frede...@ofb.net wrote:
| Hi R Devel,
| 
| I just ran into a corner case with 'strptime'. Recall that the "%OS"
| conversion accepts fractional seconds:
| 
| > strptime("17_35_14.01234.mp3","%H_%M_%OS.mp3")$sec
| [1] 14.01234
| 
| Unfortunately for my application it seems to be "greedy", in that it
| tries to parse a decimal point which might belong to the rest of the
| format:
| 
| > strptime("17_35_14.mp3","%H_%M_%OS.mp3")
| [1] NA

Maybe just don't use the optional O:

   R> strptime("17_35_14.mp3","%H_%M_%S.mp3")$sec
   [1] 14
   R> 
   R> strptime("17_35_14.mp3","%H_%M_%S.mp3")
   [1] "2017-01-10 17:35:14 CST"
   R>
   
Dirk
 
| If I use "_" instead of ".", then it works:
| 
| > strptime("17_35_14_mp3","%H_%M_%OS_mp3")
| [1] "2017-01-10 17:35:14 PST"
| 
| Perhaps a low priority, but seems like a bug to me...
| 
| Thanks,
| 
| Frederick
| 
| __
| R-devel@r-project.org mailing list
| https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] bug with strptime, %OS, and "."

2017-01-10 Thread frederik
Hi R Devel,

I just ran into a corner case with 'strptime'. Recall that the "%OS"
conversion accepts fractional seconds:

> strptime("17_35_14.01234.mp3","%H_%M_%OS.mp3")$sec
[1] 14.01234

Unfortunately for my application it seems to be "greedy", in that it
tries to parse a decimal point which might belong to the rest of the
format:

> strptime("17_35_14.mp3","%H_%M_%OS.mp3")
[1] NA

If I use "_" instead of ".", then it works:

> strptime("17_35_14_mp3","%H_%M_%OS_mp3")
[1] "2017-01-10 17:35:14 PST"

Perhaps a low priority, but seems like a bug to me...

Thanks,

Frederick

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel