-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Extended character parser for quarters #108
Conversation
R/period.R
Outdated
anytime::assertDate(x) | ||
as_yearquarter(anytime::anydate(x)) | ||
qtr_regex <- "(?i)(q|qtr|quarter)(?-i) *" | ||
if(all(grepl(paste0("\\d{4} *", qtr_regex, "\\d|", qtr_regex, "\\d *\\d{4}"), x, perl = TRUE))){ |
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.
- Can you put space around the
if-else
statement? - In the condition, can you just do
grepl(qtr_regex, x, perl = TRUE)
without checking other things?
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.
- Fixed
- Why? It's safer to match the whole expression, rather than accept an incomplete expression.
R/period.R
Outdated
anytime::assertDate(x) | ||
as_yearquarter(anytime::anydate(x)) | ||
qtr_regex <- "(?i)(q|qtr|quarter)(?-i) *" | ||
if(all(grepl(paste0("\\d{4} *", qtr_regex, "\\d|", qtr_regex, "\\d *\\d{4}"), x, perl = TRUE))){ |
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.
Can you refactor the code to extract digits only without using qtr_regrex
for quarter and year?
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.
You can refactor it - using qtr_regex
for both quarter and year is safer than just matching digits.
tests/testthat/test-index-fun.R
Outdated
@@ -81,6 +81,9 @@ test_that("some S3 methods for yearweek, yearmonth & yearquarter", { | |||
expect_is(unique(y2), "yearquarter") | |||
expect_identical(yearquarter(y), y) | |||
expect_is(y[1:2], "yearquarter") | |||
expect_equal(yearquarter("2010 Q1"), y[1]) |
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.
Can you make a new test block to include the tests, and refer to the issue in the test_that(..., {})
?
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.
Fixed.
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.
can you please create a new branch other than master?
I can use branches for the next PR - to change branches would require a new PR. |
8e46fd9
to
678b5b2
Compare
42b1cf4
to
3618415
Compare
Resolves #107
cc @robjhyndman