| Title: | Work with Microsoft Access Files |
|---|---|
| Description: | Work with Microsoft Access '.mdb' and '.accdb' files using the open source 'MDB Tools' library <https://github.com/mdbtools/mdbtools/>. The library is compiled and bundled with the package, so no external installation is required. Provides high-level helpers for reading tables, exporting to CSV or JSON, inspecting table definitions, and running SQL queries. Also exposes a full read-only 'DBI' interface for use with standard database workflows. |
| Authors: | Kiernan Nicholls [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-9229-7897>), Bruno Tremblay [ctb] (DBI interface and bundled mdbtools source) |
| Maintainer: | Kiernan Nicholls <[email protected]> |
| License: | GPL-3 | LGPL-2 |
| Version: | 0.3.1 |
| Built: | 2026-05-24 02:40:53 UTC |
| Source: | https://github.com/k5cents/mdbr |
Convert the data of a table into a delimited text string. Save the string as a character vector or write it to a text file. This direct conversion makes it easy to read tables into R or a spreadsheet.
export_mdb( file, table, output = TRUE, delim = ",", quote = "\"", quote_escape = "double", col_names = TRUE, eol = "\n", date_format = "%Y-%m-%d %H:%M:%S" )export_mdb( file, table, output = TRUE, delim = ",", quote = "\"", quote_escape = "double", col_names = TRUE, eol = "\n", date_format = "%Y-%m-%d %H:%M:%S" )
file |
Path to the Microsoft Access file. |
table |
Name of the table, list with |
output |
Controls where output is sent. |
delim |
Delimiter used to separate values. |
quote |
Single character used to quote strings. Defaults to |
quote_escape |
The type of escaping to use for quoted values, one of
|
col_names |
If |
eol |
The end of line character to use. Most commonly either |
date_format |
The format in which date columns are converted. MDB Tools
uses the |
Character string, invisible if path to file.
## Not run: export_mdb(mdb_example(), "Airlines", output = TRUE) ## End(Not run)## Not run: export_mdb(mdb_example(), "Airlines", output = TRUE) ## End(Not run)
mdb() is the canonical DBI-style constructor for connecting to Microsoft
Access '.mdb' and '.accdb' files.
mdb()mdb()
A DBI driver for '.mdb' and '.accdb' files.
db <- mdb_example() conn <- DBI::dbConnect(mdb(), dbname = db) DBI::dbListTables(conn) DBI::dbDisconnect(conn)db <- mdb_example() conn <- DBI::dbConnect(mdb(), dbname = db) DBI::dbListTables(conn) DBI::dbDisconnect(conn)
mdb-array(1) emits C source; this wrapper returns a named R list of columns
while keeping equivalent database/table inputs.
mdb_array(path, table, columns = NULL, n = -1L)mdb_array(path, table, columns = NULL, n = -1L)
path |
Path to |
table |
Table name. |
columns |
Optional character vector of columns. |
n |
Optional row limit ( |
Named list, one entry per selected column.
db <- mdbr:::.mdb_example_nwind_path() if (nzchar(db)) { arr <- mdb_array(db, "Products", columns = c("ProductID", "ProductName"), n = 2) str(arr) }db <- mdbr:::.mdb_example_nwind_path() if (nzchar(db)) { arr <- mdb_array(db, "Products", columns = c("ProductID", "ProductName"), n = 2) str(arr) }
mdb-count is a utility program distributed with MDB Tools.
It outputs the number of rows in a table.
mdb_count(path, table = NULL, where = NULL, version = FALSE)mdb_count(path, table = NULL, where = NULL, version = FALSE)
path |
Path to |
table |
Table name. |
where |
Optional SQL predicate appended to |
version |
Logical; when |
Integer row count or version string.
db <- mdbr:::.mdb_example_nwind_path() if (nzchar(db)) { mdb_count(db, "Orders") }db <- mdbr:::.mdb_example_nwind_path() if (nzchar(db)) { mdb_count(db, "Orders") }
mdbr comes bundled with a sample file from the nycflights13 package in its inst/extdata directory. This function make it easy to access.
mdb_example(path = "nycflights13.mdb")mdb_example(path = "nycflights13.mdb")
path |
path to the Microsoft Access file. |
A character string with the full path to the bundled example file.
mdb_example()mdb_example()
mdb-export is a utility program distributed with MDB Tools.
It produces CSV output for the given table. Such output is suitable for
importation into databases or spreadsheets.
mdb_export( path, table, no_header = FALSE, delimiter = ",", row_delimiter = "\n", no_quote = FALSE, quote = "\"", escape = NULL, escape_invisible = FALSE, date_format = "%Y-%m-%d", datetime_format = "%Y-%m-%d %H:%M:%S", null = "", bin = c("strip", "raw", "octal", "hex"), boolean_words = FALSE, insert = NULL, namespace = NULL, batch_size = 1L, n = -1L )mdb_export( path, table, no_header = FALSE, delimiter = ",", row_delimiter = "\n", no_quote = FALSE, quote = "\"", escape = NULL, escape_invisible = FALSE, date_format = "%Y-%m-%d", datetime_format = "%Y-%m-%d %H:%M:%S", null = "", bin = c("strip", "raw", "octal", "hex"), boolean_words = FALSE, insert = NULL, namespace = NULL, batch_size = 1L, n = -1L )
path |
Path to |
table |
Table name. |
no_header |
Logical, equivalent to |
delimiter |
Equivalent to |
row_delimiter |
Equivalent to |
no_quote |
Equivalent to |
quote |
Equivalent to |
escape |
Equivalent to |
escape_invisible |
Equivalent to |
date_format |
Equivalent to |
datetime_format |
Equivalent to |
null |
Equivalent to |
bin |
Binary mode ( |
boolean_words |
Equivalent to |
insert |
Backend for |
namespace |
Equivalent to |
batch_size |
Equivalent to |
n |
Optional row limit ( |
Used with insert, it outputs backend-specific SQL INSERT statements.
Most formatting options also apply in insert mode.
Character scalar containing CSV or SQL INSERT text.
db <- mdbr:::.mdb_example_nwind_path() if (nzchar(db)) { cat(mdb_export(db, "Products", n = 2)) }db <- mdbr:::.mdb_example_nwind_path() if (nzchar(db)) { cat(mdb_export(db, "Products", n = 2)) }
mdb-header(1) writes C files; this wrapper returns a structured summary.
mdb_header(path)mdb_header(path)
path |
Path to |
Named list with version, table names and query names.
db <- mdbr:::.mdb_example_nwind_path() if (nzchar(db)) { mdb_header(db) }db <- mdbr:::.mdb_example_nwind_path() if (nzchar(db)) { mdb_header(db) }
Hexdump MDB File (mdb-hexdump mimic)
mdb_hexdump(path, pagenumber = NULL, page_size = 4096L, n = 256L)mdb_hexdump(path, pagenumber = NULL, page_size = 4096L, n = 256L)
path |
Path to file. |
pagenumber |
Optional page index (0-based) like |
page_size |
Page size in bytes (default 4096 for modern Jet/ACE). |
n |
Number of bytes to emit. |
Single hexadecimal string.
db <- mdbr:::.mdb_example_nwind_path() if (nzchar(db)) { mdb_hexdump(db, n = 16) }db <- mdbr:::.mdb_example_nwind_path() if (nzchar(db)) { mdb_hexdump(db, n = 16) }
mdb-json is a utility program distributed with MDB Tools.
It produces JSON output for the given table. Such output is suitable for
parsing in a variety of languages.
mdb_json( path, table, date_format = "%Y-%m-%d", time_format = "%Y-%m-%d %H:%M:%S", no_unprintable = FALSE, n = -1L )mdb_json( path, table, date_format = "%Y-%m-%d", time_format = "%Y-%m-%d %H:%M:%S", no_unprintable = FALSE, n = -1L )
path |
Path to |
table |
Table name. |
date_format |
Equivalent to |
time_format |
Equivalent to |
no_unprintable |
Equivalent to |
n |
Optional row limit. |
JSON string.
db <- mdbr:::.mdb_example_nwind_path() if (nzchar(db) && requireNamespace("jsonlite", quietly = TRUE)) { mdb_json(db, "Products", n = 2) }db <- mdbr:::.mdb_example_nwind_path() if (nzchar(db) && requireNamespace("jsonlite", quietly = TRUE)) { mdb_json(db, "Products", n = 2) }
mdb-prop retrieves properties for one or more objects in an MDB database.
name is the name of the table, query, or other object.
propcol is the name of the MSysObjects column containing properties and
defaults to LvProp.
mdb_prop( path, name = NULL, propcol = "LvProp", version = FALSE, as_list = TRUE )mdb_prop( path, name = NULL, propcol = "LvProp", version = FALSE, as_list = TRUE )
path |
Path to |
name |
Object name ( |
propcol |
Property column name. Defaults to |
version |
Logical; when |
as_list |
Logical; defaults to |
A named list with one entry per element of name. Each entry is
itself a named list of named character vectors, one per property block
(e.g. "(none)" for table-level properties, or a column/field name).
Access individual values with p[["Orders"]][["(none)"]]["Description"].
db <- mdbr:::.mdb_example_nwind_path() if (nzchar(db)) { p <- mdb_prop(db, "Orders") p[["Orders"]][["(none)"]]["Description"] p2 <- mdb_prop(db, c("Orders", "Orders Qry")) }db <- mdbr:::.mdb_example_nwind_path() if (nzchar(db)) { p <- mdb_prop(db, "Orders") p[["Orders"]][["(none)"]]["Description"] p2 <- mdb_prop(db, c("Orders", "Orders Qry")) }
mdb-queries is a utility program distributed with MDB Tools.
Without query, it lists the names of all saved queries in the database.
With query, it returns the SQL text of the named query or queries.
mdb_queries( path, query = NULL, list = TRUE, newline = FALSE, delimiter = " ", as_text = FALSE, as_list = TRUE )mdb_queries( path, query = NULL, list = TRUE, newline = FALSE, delimiter = " ", as_text = FALSE, as_list = TRUE )
path |
Path to |
query |
Character vector of query names. When |
list |
Logical; when |
newline |
Logical; when |
delimiter |
Character scalar used to collapse query names when
|
as_text |
Logical; when |
as_list |
Logical; defaults to |
When query is NULL: a character vector of query names (or a
collapsed string when as_text = TRUE). When query is supplied and
as_list = TRUE: a named mdblist of SQL text strings, one per query.
With a single query and as_list = FALSE: a character scalar.
db <- mdbr:::.mdb_example_nwind_path() if (nzchar(db)) { mdb_queries(db) mdb_queries(db, "Orders Qry") }db <- mdbr:::.mdb_example_nwind_path() if (nzchar(db)) { mdb_queries(db) mdb_queries(db, "Orders Qry") }
mdb-schema is a utility program distributed with MDB Tools. It produces
DDL (data definition language) output for the given database, which can be
passed to another database to recreate the Access table structure. With
mode = "legacy" (the default), it returns a
readr col spec for the table instead.
mdb_schema( path, table = NULL, mode = c("legacy", "ddl"), condense = FALSE, namespace = NULL, backend = c("access", "sybase", "oracle", "postgres", "mysql", "sqlite"), drop_table = FALSE, not_null = TRUE, default_values = FALSE, not_empty = FALSE, comments = TRUE, indexes = TRUE, relations = TRUE, as_list = TRUE )mdb_schema( path, table = NULL, mode = c("legacy", "ddl"), condense = FALSE, namespace = NULL, backend = c("access", "sybase", "oracle", "postgres", "mysql", "sqlite"), drop_table = FALSE, not_null = TRUE, default_values = FALSE, not_empty = FALSE, comments = TRUE, indexes = TRUE, relations = TRUE, as_list = TRUE )
path |
Path to |
table |
Table name(s). For |
mode |
|
condense |
Logical; only used when |
namespace |
Prefix identifiers with namespace, equivalent to
|
backend |
Target DDL dialect. Supported values are |
drop_table |
Issue |
not_null |
Include |
default_values |
Include |
not_empty |
Include |
comments |
Include |
indexes |
Export indexes. |
relations |
Request foreign key constraints. Current library-mode implementation emits a placeholder comment; full FK export is not yet implemented. |
as_list |
Logical; defaults to |
When mode = "legacy", a readr::cols() specification (optionally
condensed via readr::cols_condense()). Requires the readr package.
When mode = "ddl" and as_list = TRUE, a named mdblist of table-level
DDL text.
db <- mdbr:::.mdb_example_nwind_path() if (nzchar(db)) { mdb_schema(db, table = "Products") mdb_schema(db, table = "Products", mode = "ddl") }db <- mdbr:::.mdb_example_nwind_path() if (nzchar(db)) { mdb_schema(db, table = "Products") mdb_schema(db, table = "Products", mode = "ddl") }
mdb-sql is a utility program distributed with MDB Tools.
It allows querying of an MDB database using a limited SQL subset language.
The supported SQL is intentionally small: single-table queries, no aggregates,
and limited WHERE support.
mdb_sql( path, statement = NULL, no_header = FALSE, no_footer = FALSE, no_pretty_print = FALSE, delimiter = "\t", input = NULL, output = NULL, as_text = FALSE )mdb_sql( path, statement = NULL, no_header = FALSE, no_footer = FALSE, no_pretty_print = FALSE, delimiter = "\t", input = NULL, output = NULL, as_text = FALSE )
path |
Path to |
statement |
SQL statement text. |
no_header |
Logical, equivalent to |
no_footer |
Logical, equivalent to |
no_pretty_print |
Logical, equivalent to |
delimiter |
Delimiter equivalent to |
input |
Input file equivalent to |
output |
Output file equivalent to |
as_text |
Logical; when |
In addition to single statements, this wrapper accepts input files similar
to mdb-sql -i file, strips go batch terminators, and executes the script
one statement at a time.
data.frame by default, or character scalar in text mode.
db <- mdbr:::.mdb_example_nwind_path() if (nzchar(db)) { mdb_sql(db, "SELECT [ProductID], [ProductName] FROM [Products] LIMIT 3;") }db <- mdbr:::.mdb_example_nwind_path() if (nzchar(db)) { mdb_sql(db, "SELECT [ProductID], [ProductName] FROM [Products] LIMIT 3;") }
mdb-tables is a utility program distributed with MDB Tools.
It outputs the names of all user tables (or other object types) in an MDB
database file.
mdb_tables( file, system = FALSE, type = c("table", "query", "systable", "any", "all", "form", "macro", "report", "linkedtable", "module", "relationship", "dbprop"), show_type = FALSE )mdb_tables( file, system = FALSE, type = c("table", "query", "systable", "any", "all", "form", "macro", "report", "linkedtable", "module", "relationship", "dbprop"), show_type = FALSE )
file |
Path to the Microsoft Access file. |
system |
Logical; include system ( |
type |
Object type to list: |
show_type |
Logical; prefix each entry with its type. Equivalent to |
A character vector of object names.
db <- mdb_example() mdb_tables(db) mdb_tables(db, type = "query")db <- mdb_example() mdb_tables(db) mdb_tables(db, type = "query")
mdb-ver will return a single line of output corresponding to the program
that produced the file: JET3 (for files produced by Access 97), JET4
(Access 2000, XP and 2003), ACE12 (Access 2007), ACE14 (Access 2010),
ACE15 (Access 2013), or ACE16 (Access 2016).
mdb_ver(path = NULL, version = FALSE)mdb_ver(path = NULL, version = FALSE)
path |
Optional database path. When omitted, the wrapper returns the mdbtools package version for backward compatibility. |
version |
Logical, equivalent to |
Single character string with file format or mdbtools version.
mdb_ver() db <- mdbr:::.mdb_example_nwind_path() if (nzchar(db)) { mdb_ver(db) }mdb_ver() db <- mdbr:::.mdb_example_nwind_path() if (nzchar(db)) { mdb_ver(db) }
mdblist
Pretty printer for multi-object text outputs returned by selected
mdb_* helpers when as_list = TRUE (default).
## S3 method for class 'mdblist' print(x, ...)## S3 method for class 'mdblist' print(x, ...)
x |
A |
... |
Unused. |
The input object, invisibly.
Reads a table directly from a Microsoft Access database using the bundled mdbtools C library. Column types are inferred from the MDB schema: integer, double, logical, POSIXct for DateTime columns, and character otherwise.
read_mdb(file, table, col_names = TRUE, col_types = NULL, ...)read_mdb(file, table, col_names = TRUE, col_types = NULL, ...)
file |
Path to the Microsoft Access file. |
table |
Name of the table, list with |
col_names |
Logical; when |
col_types |
|
... |
|
A tibble.
## Not run: read_mdb(mdb_example(), "Airlines") ## End(Not run)## Not run: read_mdb(mdb_example(), "Airlines") ## End(Not run)