| Title: | Access the Bank of Japan Time-Series Data API |
|---|---|
| Description: | An unofficial, tidy, rate-limited interface to the 'Bank of Japan Time-Series Data Search' API. Search series metadata, retrieve observations by series code or hierarchy, follow pagination automatically, and work with normalized long or wide data frames. The API does not require an API key. |
| Authors: | Kenji Miyazaki [aut, cre] |
| Maintainer: | Kenji Miyazaki <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-10-16 08:19:19 UTC |
| Source: | https://github.com/kenjimyzk/bojapi |
The BOJ asks publishers of services using its API to show a specified credit and notify its Research and Statistics Department. The terms can change without prior notice; verify the linked official notice before releasing a service.
boj_api_credit(lang = c("en", "jp"))boj_api_credit(lang = c("en", "jp"))
lang |
Credit language, |
A named list containing the requested credit, contact address, subject line, and official notice URL.
boj_api_credit("en") boj_api_credit("jp")$creditboj_api_credit("en") boj_api_credit("jp")$credit
boj_cache() is the counterpart to WDI::WDIcache(): it retrieves current
BOJ metadata and saves it to the local cache used by boj_search(). When
db = NULL, all databases in boj_databases() are refreshed. This takes
about one minute with the default one-second interval.
boj_cache( db = NULL, lang = boj_default("lang", "en"), refresh = TRUE, max_age = 24 * 60 * 60, cache_dir = boj_default("cache_dir", tools::R_user_dir("bojapi", "cache")), include_groups = TRUE, wait = boj_default("wait", 1), timeout = boj_default("timeout", 30), retries = boj_default("retries", 3), action = "refresh" )boj_cache( db = NULL, lang = boj_default("lang", "en"), refresh = TRUE, max_age = 24 * 60 * 60, cache_dir = boj_default("cache_dir", tools::R_user_dir("bojapi", "cache")), include_groups = TRUE, wait = boj_default("wait", 1), timeout = boj_default("timeout", 30), retries = boj_default("retries", 3), action = "refresh" )
db |
Character vector of database identifiers, or |
lang |
Response language, |
refresh |
Ignore current cache entries and download fresh metadata.
Used only when |
max_age |
Maximum cache age in seconds; default 86,400 (24 hours). |
cache_dir |
Metadata cache directory. |
include_groups |
Include hierarchy-heading rows whose |
wait |
Requested seconds between automatic requests. The default is one second, and values below one are treated as one whenever another request is needed, to avoid high-frequency access prohibited by the BOJ. |
timeout |
Request timeout in seconds. |
retries |
Number of retries for network and transient server errors. |
action |
Cache operation: |
Set action = "clear" to remove matching cache entries, or
action = "prune" to remove only expired or invalid entries. For these
management actions, db = NULL targets all bojapi metadata cache files in
cache_dir, including both languages. Supplying db limits the operation
to those databases and the selected lang. Other files and directories are
never recursively removed.
For action = "refresh", a combined metadata tibble that is also
written to the per-database cache. For "clear" and "prune", a tibble
reporting each matched file, path, status, and reason.
## Not run: current_fx_metadata <- boj_cache("FM08") all_metadata <- boj_cache() boj_cache(action = "prune") boj_cache("FM08", action = "clear") ## End(Not run)## Not run: current_fx_metadata <- boj_cache("FM08") all_metadata <- boj_cache() boj_cache(action = "prune") boj_cache("FM08", action = "clear") ## End(Not run)
boj_data() is the main data function. It accepts one or more BOJ series
codes, splits requests into safe batches of 250 codes, follows
NEXTPOSITION until complete, and returns one observation per row. All codes
in a BOJ code request must have the same frequency.
boj_data( db, code, start_date = NULL, end_date = NULL, lang = boj_default("lang", "en"), wide = FALSE, wait = boj_default("wait", 1), timeout = boj_default("timeout", 30), retries = boj_default("retries", 3) )boj_data( db, code, start_date = NULL, end_date = NULL, lang = boj_default("lang", "en"), wide = FALSE, wait = boj_default("wait", 1), timeout = boj_default("timeout", 30), retries = boj_default("retries", 3) )
db |
BOJ database identifier, such as |
code |
Character vector of series codes without the database prefix.
For example, use |
start_date, end_date
|
Optional BOJ period codes. Accepted request forms
are |
lang |
Response language, |
wide |
If |
wait |
Requested seconds between automatic requests. The default is one second, and values below one are treated as one whenever another request is needed, to avoid high-frequency access prohibited by the BOJ. |
timeout |
Request timeout in seconds. |
retries |
Number of retries for network and transient server errors. |
A named code vector creates convenient aliases, following the style of
WDI::WDI(). The original BOJ code is always retained in series_code.
A tibble. Long output contains db, series, series_code, name,
unit, frequency, category, last_update, time, date, and
value. time preserves the exact BOJ period code. date is the first
day of non-daily periods (April 1 for fiscal years); use time when exact
period semantics matter.
## Not run: fx <- boj_data( db = "FM08", code = c(usd_yen = "FXERM07"), start_date = "202401", end_date = "202412" ) boj_data( "FM08", c(usd_yen = "FXERM07", euro_yen = "FXERM09"), start_date = "202401", wide = TRUE ) ## End(Not run)## Not run: fx <- boj_data( db = "FM08", code = c(usd_yen = "FXERM07"), start_date = "202401", end_date = "202412" ) boj_data( "FM08", c(usd_yen = "FXERM07", euro_yen = "FXERM09"), start_date = "202401", wide = TRUE ) ## End(Not run)
Returns the database identifiers accepted by db in the BOJ API. The
registry follows the February 18, 2026 API manual. New databases may be
accepted by the API before this package registry is updated.
boj_databases()boj_databases()
A tibble with database code, English category, and English and Japanese database names.
boj_databases() subset(boj_databases(), grepl("Exchange", name_en))boj_databases() subset(boj_databases(), grepl("Exchange", name_en))
Uses the BOJ layer API to retrieve all series matching a database hierarchy
and frequency. The function follows NEXTPOSITION automatically. A layer
condition that identifies more than 1,250 series is rejected by the BOJ API;
this count is evaluated before the frequency filter.
boj_layer( db, frequency, layer, start_date = NULL, end_date = NULL, lang = boj_default("lang", "en"), wide = FALSE, wait = boj_default("wait", 1), timeout = boj_default("timeout", 30), retries = boj_default("retries", 3) )boj_layer( db, frequency, layer, start_date = NULL, end_date = NULL, lang = boj_default("lang", "en"), wide = FALSE, wait = boj_default("wait", 1), timeout = boj_default("timeout", 30), retries = boj_default("retries", 3) )
db |
BOJ database identifier. |
frequency |
One of |
layer |
One to five hierarchy values supplied as a vector or a
comma-separated string. |
start_date, end_date
|
Optional BOJ period codes. Accepted request forms
are |
lang |
Response language, |
wide |
If |
wait |
Requested seconds between automatic requests. The default is one second, and values below one are treated as one whenever another request is needed, to avoid high-frequency access prohibited by the BOJ. |
timeout |
Request timeout in seconds. |
retries |
Number of retries for network and transient server errors. |
A long or wide tibble with the same structure as boj_data().
## Not run: boj_layer( db = "BP01", frequency = "M", layer = c(1, 1, 1), start_date = "202504", end_date = "202509" ) ## End(Not run)## Not run: boj_layer( db = "BP01", frequency = "M", layer = c(1, 1, 1), start_date = "202504", end_date = "202509" ) ## End(Not run)
Downloads the complete metadata table for one BOJ database. Metadata
includes both hierarchy headings (blank series_code) and actual series.
By default it is cached for 24 hours, matching the API's daily metadata
update cycle and reducing load on the BOJ service.
boj_metadata( db, lang = boj_default("lang", "en"), cache = TRUE, refresh = FALSE, max_age = 24 * 60 * 60, cache_dir = boj_default("cache_dir", tools::R_user_dir("bojapi", "cache")), include_groups = TRUE, timeout = boj_default("timeout", 30), retries = boj_default("retries", 3), wait = boj_default("wait", 1) )boj_metadata( db, lang = boj_default("lang", "en"), cache = TRUE, refresh = FALSE, max_age = 24 * 60 * 60, cache_dir = boj_default("cache_dir", tools::R_user_dir("bojapi", "cache")), include_groups = TRUE, timeout = boj_default("timeout", 30), retries = boj_default("retries", 3), wait = boj_default("wait", 1) )
db |
BOJ database identifier, such as |
lang |
Response language, |
cache |
Whether to read and write the on-disk metadata cache. |
refresh |
If |
max_age |
Maximum cache age in seconds; default 86,400 (24 hours). |
cache_dir |
Metadata cache directory. |
include_groups |
Include hierarchy-heading rows whose |
timeout |
Request timeout in seconds. |
retries |
Number of retries for network and transient server errors. |
wait |
Requested seconds between automatic requests. The default is one second, and values below one are treated as one whenever another request is needed, to avoid high-frequency access prohibited by the BOJ. |
A tibble with normalized metadata. start_time and end_time
preserve exact BOJ period codes. Parsed date columns indicate the first day
of each period and are NA for hierarchy headings.
## Not run: metadata <- boj_metadata("FM08", lang = "jp") subset(metadata, is_series) ## End(Not run)## Not run: metadata <- boj_metadata("FM08", lang = "jp") subset(metadata, is_series) ## End(Not run)
Searches current BOJ metadata in the same spirit as WDI::WDIsearch().
Supply a database to fetch/cache metadata, or pass a metadata tibble directly
for an offline or reproducible search.
boj_search( pattern, db = NULL, fields = c("series_code", "name", "category", "notes"), regex = FALSE, ignore_case = TRUE, metadata = NULL, lang = boj_default("lang", "en"), cache = TRUE, refresh = FALSE, max_age = 24 * 60 * 60, cache_dir = boj_default("cache_dir", tools::R_user_dir("bojapi", "cache")), include_groups = FALSE, wait = boj_default("wait", 1), timeout = boj_default("timeout", 30), retries = boj_default("retries", 3) )boj_search( pattern, db = NULL, fields = c("series_code", "name", "category", "notes"), regex = FALSE, ignore_case = TRUE, metadata = NULL, lang = boj_default("lang", "en"), cache = TRUE, refresh = FALSE, max_age = 24 * 60 * 60, cache_dir = boj_default("cache_dir", tools::R_user_dir("bojapi", "cache")), include_groups = FALSE, wait = boj_default("wait", 1), timeout = boj_default("timeout", 30), retries = boj_default("retries", 3) )
pattern |
One non-empty search string or regular expression. |
db |
One or more database identifiers. Not needed when |
fields |
Metadata columns to search. Defaults to series code, name, category, and notes. |
regex |
Treat |
ignore_case |
Ignore letter case. |
metadata |
Optional data frame returned by |
lang |
Response language, |
cache |
Whether to read and write the on-disk metadata cache. |
refresh |
If |
max_age |
Maximum cache age in seconds; default 86,400 (24 hours). |
cache_dir |
Metadata cache directory. |
include_groups |
Include matching hierarchy-heading rows. |
wait |
Requested seconds between automatic requests. The default is one second, and values below one are treated as one whenever another request is needed, to avoid high-frequency access prohibited by the BOJ. |
timeout |
Request timeout in seconds. |
retries |
Number of retries for network and transient server errors. |
A filtered metadata tibble.
## Not run: boj_search("U.S. Dollar", db = "FM08") boj_search("FXERM07", db = "FM08", lang = "jp") boj_search("exchange|euro", db = "FM08", regex = TRUE) ## End(Not run)## Not run: boj_search("U.S. Dollar", db = "FM08") boj_search("FXERM07", db = "FM08", lang = "jp") boj_search("exchange|euro", db = "FM08", regex = TRUE) ## End(Not run)