Last data update: 2014.03.03

R: Import tables and queries from Microssoft Office Access(.mdb)
access_importR Documentation

Import tables and queries from Microssoft Office Access(.mdb)

Description

Directly connect (and disconnect at the end) with the Microssoft Office Access database using the RODBC package and read one or multiple data sets. It can read both tables and SQL queries depending on the input instructions. It automatically detects date variables that are stored also with date format in the original data set.

Usage

access_import(file,table_names,ntab=length(table_names),
SQL_query=rep(F,times=ntab),where_sql=c(),out.format="d-m-yy",uid="",pwd="",...)

Arguments

file

The path to the file with .mdb extension.

table_names

A single character or a character vector containing either the names of the tables to read or the SQL queries to perform. Each position must contain only one table name or SQL querie.The format of the SQL queries must follow the one described in sqlQuery.

where_sql

If table_names is a vector, where_sql must contain the position of the SQL queries within the table_names vector. Ex: If the first and the fifth elements of table_names are SQL queries (the other ones are table names) the vector where_sql should be where_sql=c(1,5) .

out.format

a character specifying the format for printing the date variables.

ntab

The number of tables to import, equal to the number of table names.

SQL_query

Auxiliar vector to perform the function.

uid

see odbcConnect .

pwd

see odbcConnect .

...

see odbcConnect, sqlFetch, sqlQuery.

Details

By default, the function gives to each data set the name specified in table_names, so the sql queries data set have probably an inappropriate name. It can be easily renamed using names.

Value

A data frame or a data frame list containing the data requested from the Microsoft Office Access file.

Note

The function don't contribute in the date variables detection, it just process with the Chron package the ones who has been automatically detected.

See Also

access_export,var_view sqlFetch, sqlQuery

Examples


## Not run: 
x<-access_import(file="mydata.mdb",
                    table_names=c("table1","table2",
                    "Select * From table1 inner join table2 on table.var1=table2.var2","table3")
                    ,where_sql=c(3))


## End(Not run)

Results