Comments (11)
It's tricky. I think the 'leading stuff' maybe be best handled by an added 'filter' you could add:
R> anydate(gsub("(^[a-z ]*)", "", "asfdsfsdf 2020-01-01"))
[1] "2020-01-01"
R>
The second one is a no-no as our parsers aim to create proper date or datetime objects. And a pair on month and year is simply not a date. So there too you may have to build something on top of what we offer.
from anytime.
Thanks. The regex is a simple workaround for that one scenario. It doesn't help in two sub-cases I have:
- Leading numbers in the string before the date
- Date sub-strings with a format like "May 20, 2020".
As far as the need for proper objects, admittedly I'm far from an expert on how the parsers work. My suggestion is not that you only have a month and year, but that you have a simple set of rules to impute missing parameters (day =1, month/year = current month/year).
from anytime.
The package makes no claim to help with any possible date formats. Some remain too irregular. There is no way around this.
It does offer you ways to accomodate the need for special treatment, see help(addFormats)
.
I still think we should close this.
from anytime.
thanks
from anytime.
BTW your last example already works:
R> anytime::anydate("May 20, 2020")
[1] "2020-05-20"
R>
from anytime.
That one works, with no leading text. This doesn't work:
anydate(gsub("(^[a-z ]*)", "", "asfdsfsdf May 20, 2020"))
from anytime.
Regular expressions are very powerful. It pays off to read up a little. Here [a-z]
means letters; use [a-z0-9]
and you may need to add punctuation etc -- this is no longer an anytime issue.
Best of luck, and I hope you continue to find anytime useful, even with challenging data.
from anytime.
addFormats
is promising for me. Thank you for sharing that. Is the addition of a format permanent, just for the session, something else?
anytime::anydate("May 2020")
[1] NA
anytime::addFormats("%b %Y")
anytime::anydate("May 2020")
[1] "2020-05-01"
from anytime.
Just for the session. But nothing is stopping you from adding library(anytime); addFormats(c("....". "..."))
to your R startup. Or maybe to the scripts or functions you use for this project.
from anytime.
Same logic also for date times. anytime
doesn't like HH:MM with no :SS. getFormats
always has %H:%M:%S. And then anytime
also doesn't like am/pm either...? I don't see that in any of the formats. I'm opening a separate thread about time zones.
from anytime.
Just for the session. But nothing is stopping you from adding
library(anytime); addFormats(c("....". "..."))
to your R startup. Or maybe to the scripts or functions you use for this project.
Yep understood, just making sure I knew if it was necessary. I'd probably to it on a project/process-level. I use anytime
in almost every project and I've never needed to alter the formats.
from anytime.
Related Issues (20)
- UK v US formats HOT 2
- Process only unique values for speed, please :) HOT 27
- Time is silently scrubbed when using certain string date time formats HOT 3
- Add argument for default MM/DD to add to just YYYY inputs HOT 1
- timedatectl problem on HPC? HOT 2
- Failed to activate service 'org.freedesktop.timedate1' on Google Cloud VM HOT 9
- month year specification HOT 7
- Could anydate support nanotime ? HOT 4
- Returning NA value HOT 3
- European vs US date formats HOT 3
- Feature request: function to return which format was recognized. HOT 3
- Anytime errors with length 1 NA HOT 6
- Chinese date format suggestion HOT 3
- just yyyy-mm-dd hh:mm:ss but not AEST suffix HOT 5
- anytime() sometimes returns the wrong date HOT 2
- Inconsistent handling of vectors with unknown values HOT 1
- Trivial conversion to NA HOT 1
- time is always one-hour early HOT 3
- Warn for NA's caused by `anydate()` HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anytime.