对于Windows和Mac,以编程方式将Access(.mdb)文件读入R [英] Programmatically read Access (.mdb) files into R for both Windows and Mac

查看:366
本文介绍了对于Windows和Mac,以编程方式将Access(.mdb)文件读入R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个打开的数据包,其内容为

I am trying to write an open data package that reads New York State education data into R. That data are provided as an Access database.

我想编写一个下载,读取和导入这些文件的功能,并且希望跨平台支持它. 现有的方法建议安装一个R的32位版本,不适合编程访问.

I want to write a function that downloads, reads, and imports those files, and I want it to be supported across platforms. The existing approach suggests installing a 32-bit version of R, which does not fit the bill for programmatic access.

对#RStats的浏览表明,这是一个常见的痛点( 1 2 3 4 )

A tour of #RStats suggests that this is a common pain point (1, 2, 3, 4)

在OS X/Linux上,您可以使用Hmisc中的mdb.get 程序包,前提是您有一个名为mdb-tools的第三方库.但这似乎对Windows没有什么帮助.

On OS X/Linux, you can use mdb.get from the Hmisc package, provided that you have a third party library called mdb-tools. But this seems to be of little help for Windows.

一个被接受的答案将读取链接在上方的.mdb文件集成到Windows,OS X和Linux中的R中.

An accepted answer will read the .mdb file linked above into R across Windows, OS X, and Linux.

推荐答案

仅使用RODBC怎么样?您还可以下载并使用mdb文件(例如直接在mdb内部进行查询/查看吗?)

How about just with RODBC? Can you also download and use the mdb file (e.g. to make queries/views directly inside the mdb?)

我通常使用以下代码块将数据从Access dbs加载到R中:

I usually load data from Access dbs into R with the following code chunk:

# read in the data
library(RODBC)
db <- odbcDriverConnect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};
                        DBQ=C:\\Path\\To\\Database\\my_db.accdb")

# Get data
data <- as_tibble(sqlFetch (db , "Table or Query Name", rownames=TRUE))

这篇关于对于Windows和Mac,以编程方式将Access(.mdb)文件读入R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆