From frederik at ofb.net  Thu Jan 12 22:59:11 2017
From: frederik at ofb.net (frederik at ofb.net)
Date: Thu, 12 Jan 2017 13:59:11 -0800
Subject: [Rd] bug with strptime, %OS, and "."
In-Reply-To: <C750A9148B73B84EB6293187A5F7DA75D9208E8B@GROWLER.ern.nps.edu>
References: <20170111014855.GI29294@ofb.net>
	<22645.38081.776727.305032@max.nulle.part>
	<20170111025857.GJ29294@ofb.net>
	<C750A9148B73B84EB6293187A5F7DA75D9208E8B@GROWLER.ern.nps.edu>
Message-ID: <20170112215911.GP29294@ofb.net>

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 +0000, 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: 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 "."
frederik at ofb.net