From scupton at nps.edu  Wed Jan 11 14:36:07 2017
From: scupton at nps.edu (Upton, Stephen (Steve) (CIV))
Date: Wed, 11 Jan 2017 13:36:07 +0000
Subject: [Rd] bug with strptime, %OS, and "."
In-Reply-To: <20170111025857.GJ29294@ofb.net>
References: <20170111014855.GI29294@ofb.net>
	<22645.38081.776727.305032@max.nulle.part>
	<20170111025857.GJ29294@ofb.net>
Message-ID: <C750A9148B73B84EB6293187A5F7DA75D9208E8B@GROWLER.ern.nps.edu>

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: scupton at nps.edu
SIPR: uptonsc at nps.navy.smil.mil
SEED Center web site: http://harvest.nps.edu
-----Original Message-----
From: R-devel [mailto:r-devel-bounces at r-project.org] On Behalf Of
frederik at 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, frederik at 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 at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


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