library(toOrdinal)
is_html_output = function() {
  knitr::opts_knit$get("rmarkdown.pandoc.to")=="html"
}
knitr::opts_chunk$set(
    collapse = TRUE,
    comment = "",
    prompt=TRUE,
    fig.dpi = 96
            )
if (is_html_output()) {
    options(width=1000)
}

Introduction

The package toOrdinal contains a single function toOrdinal that converts a cardinal number (e.g., 9) into its ordinal counterpart (e.g., 9th). Because such conversions are language specific, the conversions are specific to a supported language. At present, the package implements English, French, German, Spanish, and Swedish. For example,

Use

After installing the package from either CRAN or GitHub, it's simple to convert a cardinal to an ordinal number.

To convert cardinal to ordinal numbers in English (the default), supply the cardinal number to toOrdinal.

toOrdinal(5)

Conversion in other languages are performed by supplying the appropriate language to the language argument:

toOrdinal(5, language="German")
toOrdinal(5, language="French")
toOrdinal(5, language="Spanish")
toOrdinal(5, language="Swedish")

Current languages supported include: Dutch, English, German, French, Spanish, and Swedish.

Since Version 1.1, the function toOrdinalDate converts calendar dates to a long format, ordinal form.

toOrdinalDate()
toOrdinalDate("2017-12-25")

If no argument is provided to toOrdinalDate, then the current date derived from Sys.date() is used to created to ordinal version of the calendar date. If a date is supplied, then a character string of the form "YYYY-MM-DD" must be supplied that is then converted to a formal date. Like with the function toOrdinal the potential exists for multiple language support with toOrdinalDate. However, the only language currently supported by toOrdinalDate is English.

Examples

The first argument, n, is the cardinal number to be converted to an ordinal number:

sapply(1:10, toOrdinal)

Contributions & Requests

If you have contribution (for example, another language) or a feature request for the toOrdinal package, don't hesitate to write or set up an issue on GitHub. Current new features include the possiblity of converting cardinal numbers to ordinal words (e.g., 8 to eighth).



CenterForAssessment/toOrdinal documentation built on Oct. 27, 2023, 12:17 p.m.