Skip to content
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

Closed
wants to merge 2 commits into from
Closed

Extended character parser for quarters #108

wants to merge 2 commits into from

Conversation

mitchelloharawild
Copy link
Member

Resolves #107
cc @robjhyndman

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))){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Can you put space around the if-else statement?
  2. In the condition, can you just do grepl(qtr_regex, x, perl = TRUE) without checking other things?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Fixed
  2. 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))){
Copy link
Member

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?

Copy link
Member Author

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.

@@ -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])
Copy link
Member

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(..., {})?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@earowang earowang self-requested a review April 5, 2019 02:23
Copy link
Member

@earowang earowang left a 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?

@mitchelloharawild
Copy link
Member Author

I can use branches for the next PR - to change branches would require a new PR.

@earowang earowang force-pushed the master branch 2 times, most recently from 8e46fd9 to 678b5b2 Compare April 17, 2019 13:38
@earowang earowang force-pushed the master branch 3 times, most recently from 42b1cf4 to 3618415 Compare April 27, 2019 07:31
@earowang earowang closed this May 24, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom yearquarter() character parser
2 participants