Skip to content

Conversation

@larmarange
Copy link
Contributor

prefix, suffix, big.mark and rules (allowing to provide custom rules)

#'
#' # Custom rules for French
#' french <- list(
#' er = "^1$",
Copy link
Member

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?

Copy link
Contributor Author

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]$",
Copy link
Member

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 = '.')

Copy link
Contributor Author

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

Copy link
Contributor Author

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

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.

Copy link
Contributor Author

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(
Copy link
Member

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.

Copy link
Contributor Author

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()

@larmarange
Copy link
Contributor Author

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")
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 please add a test for 101st, too?

R/formatter.r Outdated
list(
er = "^1$",
nd = "^2$",
e = "([0-9]+)[12]$",
Copy link
Member

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

Copy link
Member

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.

@larmarange
Copy link
Contributor Author

done, bullet news added and merge conflict solved

`prefix`, `suffix`, `big.mark` and `rules` allowing to provide custom rules
@hadley hadley merged commit fcfb042 into r-lib:master Jul 9, 2018
@larmarange larmarange deleted the ordinal_format branch July 10, 2018 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants