isocurrencies provides the ISO 4217 currency codes with their numeric codes,
names and minor units, and helpers to check codes and round amounts. The data
is ISO 4217 list one as SIX, the maintenance
agency of the standard, publishes it. The package has no dependencies.
Using rpx:
rpx add isocurrenciesUsing base R, from a downloaded GitHub release:
R CMD INSTALL isocurrencies_<version>.tar.gzlibrary(isocurrencies)
ISO_4217[ISO_4217$Letter == "KWD", ]
#> Letter Numeric Currency Minor_Units
#> 76 KWD 414 Kuwaiti Dinar 3
is_iso_currency(c("EUR", "GBp"))
#> [1] TRUE FALSE
assert_iso_currency(c("EUR", "GBp", "LOC"))
#> Error: Not an ISO 4217 currency code: GBp, LOC
iso_currency_minor_units(c("EUR", "JPY", "XAU"))
#> [1] 2 0 NA
round_to_minor_units(c(2.675, 1234.5, 10.123456), c("EUR", "JPY", "XAU"))
#> [1] 2.68000 1235.00000 10.12346Codes are case-sensitive: the pence code GBp is not GBP.
round_to_minor_units() rounds half up, away from zero, unlike round().
Codes that are not cash, such as gold (XAU), have no minor units, and their
amounts stay unrounded.
A weekly workflow compares data-raw/ISO_4217.csv with the list SIX publishes
and fails when they differ. To update, run from the package root:
python3 data-raw/iso_4217.py
Rscript data-raw/build_data.RThen review the diff of data-raw/ISO_4217.csv, update the date in
R/data.R, run roxygen2::roxygenise(), and release a new version.
Pushing a tag matching the version in DESCRIPTION (for example, v0.1.0)
builds the source package and publishes a
GitHub Release with
the archive isocurrencies_<version>.tar.gz and SHA256SUMS. The package has
no compiled code, so the source archive installs on every platform.