New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

as_date no longer supports argument "format" #607

Closed
ian-price opened this Issue Nov 9, 2017 · 8 comments

Comments

Projects
None yet
4 participants
@ian-price

ian-price commented Nov 9, 2017

Between versions 1.6.0 and 1.7.1, the function as_date lost the ability to use the argument "format". I was using this when the date was embedded in part of the text.
the command

as_date(MY_INPUT, format = "MY_TEXT_%Y%m%d") 

returns an error in 1.7.1

Error in .local(x, ...) : unused argument (format = "MY_TEXT_%Y%m%d")
@vspinu

This comment has been minimized.

Member

vspinu commented Nov 9, 2017

Well, technically format argument was never part of the API, and it worked for character vectors because in 1.6.0 it did as.Date. In 1.7.0 a range of issues with character parsing were fixed (#598, #597, #536) and that means format argument can longer work. Sorry about that. You can use any of the available parser functions in lubridate - parse_date_time, parse_date_time2 or fast_strptime.

On your string, the simplest ymd(MY_INPUT) should work.

@ian-price

This comment has been minimized.

ian-price commented Nov 9, 2017

Thanks for the quick response. For my needs, I replaced it with as.Date, so I'm fine. Thank you for the other suggestions.
I just wanted to report the change in functionality as I never know whether a change like this is intended or a side-effect. Sounds like it's intended, so I'll close the issue.

@ian-price ian-price closed this Nov 9, 2017

@vspinu vspinu reopened this Nov 9, 2017

@vspinu

This comment has been minimized.

Member

vspinu commented Nov 9, 2017

as_date is advertised as drop-in replacement for as.Date. I will try to fix this.

@huftis

This comment has been minimized.

huftis commented Nov 17, 2017

Note that as_datetime() is also advertised as a drop-in replacement for as.POSIXct(), but doesn’t support the format argument, something as.POSIXct() does. But wouldn’t it be cleaner to have as_date() and as_datetime() not support the format argument (i.e. the current behaviour)? If people want to parse characters as dates or datetimes, they can easily use parse_date() and parse_datetime(), which does support a format argument, and which are drop-in replacements for as.Date() and as.POSIXct().

@vspinu

This comment has been minimized.

Member

vspinu commented Nov 17, 2017

parse_date and parse_datetime are not part of lubridate. In any case, parsers are not drop-ins for as.Date because they work on strings only.

I think, the best is to leave format argument to character methods as before. The issues is that lubridate parsers are not equivalent to strptime and one would need to treat this particular case specially and redirect it to strptime internally. This is how I plan to fix this at the moment.

@vspinu vspinu closed this in 7c04abd Jan 28, 2018

@BastienFR

This comment has been minimized.

BastienFR commented Mar 5, 2018

The argument format should be remove from the help file if it's not used anymore. In my case, with lubridate_1.7.3, ?as_date gives a page with format. It's very confusing.

@vspinu

This comment has been minimized.

Member

vspinu commented Mar 5, 2018

It is supported.

@BastienFR

This comment has been minimized.

BastienFR commented Mar 5, 2018

Humm.... I feel bad now, it was a bug on my side, sending a numeric vector (for which format isn't supported, which makes sense) vs a character vector for which it is... my bad, sorry, I'm so used to work with date as characters...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment