Learn R Programming

Hmisc (version 4.1-0)

mdb.get: Read Tables in a Microsoft Access Database

Description

Assuming the mdb-tools package has been installed on your system and is in the system path, mdb.get imports one or more tables in a Microsoft Access database. Date-time variables are converted to dates or chron package date-time variables. The csv.get function is used to import automatically exported csv files. If tables is unspecified all tables in the database are retrieved. If more than one table is imported, the result is a list of data frames.

Usage

mdb.get(file, tables=NULL, lowernames=FALSE, allow=NULL,
        dateformat='%m/%d/%y', mdbexportArgs='-b strip', ...)

Arguments

file

the file name containing the Access database

tables

character vector specifying the names of tables to import. Default is to import all tables. Specify tables=TRUE to return the list of available tables.

lowernames

set this to TRUE to change variable names to lower case

allow

a vector of characters allowed by R that should not be converted to periods in variable names. By default, underscores in variable names are converted to periods as with R before version 1.9.

dateformat

see cleanup.import. Default is the usual Access format used in the U.S.

mdbexportArgs

command line arguments to issue to mdb-export. Set to '' to omit '-b strip'.

arguments to pass to csv.get

Value

a new data frame or a list of data frames

Details

Uses the mdbtools package executables mdb-tables, mdb-schema, and mdb-export (with by default option -b strip to drop any binary output). In Debian/Ubuntu Linux run apt get install mdbtools. cleanup.import is invoked by csv.get to transform variables and store them as efficiently as possible.

See Also

data.frame, cleanup.import, csv.get, Date, chron

Examples

Run this code
# NOT RUN {
# Read all tables in the Microsoft Access database Nwind.mdb
d <- mdb.get('Nwind.mdb')
contents(d)
for(z in d) print(contents(z))
# Just print the names of tables in the database
mdb.get('Nwind.mdb', tables=TRUE)
# Import one table
Orders <- mdb.get('Nwind.mdb', tables='Orders')
# }

Run the code above in your browser using DataLab