-
Notifications
You must be signed in to change notification settings - Fork 1k
Added format specifier for yearqtr #7713
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
base: master
Are you sure you want to change the base?
Changes from all commits
8adf4eb
3ed57e1
a8287ac
9e531a3
8c045f7
c325bee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21585,3 +21585,12 @@ close(con) | |
| file.create(f <- tempfile()) | ||
| test(2367.6, fread(file(f)), data.table(), warning="Connection has size 0.") | ||
| unlink(f) | ||
|
|
||
| # yearqtr() could optionally output 2025Q4 format #7694 | ||
| x = c("1111-11-11", "2019-01-01", "2019-02-28", "2019-03-01", "2019-12-31", "2020-02-29", "2020-03-01", "2020-12-31", "2040-01-01", "2040-12-31", "2100-03-01", NA) | ||
| test(2368.1, yearqtr(x, format="numeric"), c(1111.75, 2019, 2019, 2019, 2019.75, 2020, 2020, 2020.75, 2040, 2040.75, 2100, NA)) | ||
| test(2368.2, yearqtr(x, format="numeric"), yearqtr(x)) # numeric is the default, preserves backwards compatibility | ||
| test(2368.3, yearqtr(x, format="character"), c("1111Q4", "2019Q1", "2019Q1", "2019Q1", "2019Q4", "2020Q1", "2020Q1", "2020Q4", "2040Q1", "2040Q4", "2100Q1", NA_character_)) | ||
| test(2368.4, yearqtr("2016-08-03 01:02:03.45", format="character"), "2016Q3") | ||
| test(2368.5, yearqtr(NA, format="character"), NA_character_) | ||
| test(2368.6, yearqtr(x, format="invalid"), error="should be one of") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pls delete test case 6, since you are essentially testing for the R error message of |
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -98,8 +98,7 @@ month(x) | |||||||
| quarter(x) | ||||||||
| year(x) | ||||||||
| yearmon(x) | ||||||||
| yearqtr(x) | ||||||||
|
|
||||||||
| yearqtr(x, format = c("numeric", "character")) | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
reinstate deletion of missing line |
||||||||
| } | ||||||||
|
|
||||||||
| \arguments{ | ||||||||
|
|
@@ -115,6 +114,7 @@ yearqtr(x) | |||||||
| the S3 generic.} | ||||||||
| \item{units}{one of the units listed for truncating. May be abbreviated.} | ||||||||
| \item{ms}{ For \code{as.ITime} methods, what should be done with sub-second fractions of input? Valid values are \code{'truncate'} (floor), \code{'nearest'} (round), and \code{'ceil'} (ceiling). See Details. } | ||||||||
| \item{format}{format is either \code{"numeric"} (default) or \code{"character"}. \code{"character"} formats the result as \code{"2025Q4"}.} | ||||||||
| } | ||||||||
| \details{ | ||||||||
| \code{IDate} is a date class derived from \code{Date}. It has the same | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would go with allocating NA vector first, and then filling up non-NA, less input to paste, which needs to populate global string cache on each string.