-
Notifications
You must be signed in to change notification settings - Fork 117
New arguments for ordinal_format
#149
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
Conversation
| #' | ||
| #' # Custom rules for French | ||
| #' french <- list( | ||
| #' er = "^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.
Does this work for 101? In English it would be 101st, but in French 101e?
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.
Yes, in French it is "101e" and "1001e", "er" is used only for 1.
R/formatter.r
Outdated
| #' french <- list( | ||
| #' er = "^1$", | ||
| #' nd = "^2$", | ||
| #' e = "([0-9]+)[12]$", |
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.
What happens if a number matches multiple regular expressions? If it return the first match, we could make the fallbacks (in both French and English) simpler by matching anything (i.e. e = '.')
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 have done a quick test. If a number match two or more rules, two or more values will be returned. I will have to update the code to consider only the first results
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.
corrected
R/formatter.r
Outdated
| #' @param x A numeric vector of positive values to format. | ||
| #' @param prefix,suffix Symbols to display before and after value. | ||
| #' @param big.mark Character used between every 3 digits to separate thousands. | ||
| #' @param rules Custom rules for computing ordinal indicators (list of regular |
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.
Maybe: Named list of regular expressions, match in order. Name gives suffix, and value specifies which numbers to match.
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.
done
R/formatter.r
Outdated
| rules = NULL, ...) { | ||
| stopifnot(all(x > 0)) | ||
| if (is.null(rules)) { | ||
| rules <- list( |
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.
Maybe we should make this ordinal_english() and export it? Then we can use as the default argument, and users can easily see what the default rules are.
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.
done
also added ordinal_french() and ordinal_spanish()
0bd819e to
ecbb8d7
Compare
|
Note: I will resolve conflicts once other PRs merged |
| expect_equal(ordinal(4), "4th") | ||
| expect_equal(ordinal(11), "11th") | ||
| expect_equal(ordinal(12), "12th") | ||
| expect_equal(ordinal(21), "21st") |
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 add a test for 101st, too?
R/formatter.r
Outdated
| list( | ||
| er = "^1$", | ||
| nd = "^2$", | ||
| e = "([0-9]+)[12]$", |
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.
Now I think you can simplify this so that e matches anything
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.
And similarly, English just needs a fall back to th if nothing else matches.
ecbb8d7 to
e0c3719
Compare
|
done, bullet news added and merge conflict solved |
`prefix`, `suffix`, `big.mark` and `rules` allowing to provide custom rules
e0c3719 to
93ae013
Compare
prefix,suffix,big.markandrules(allowing to provide custom rules)