对于Windows和Mac,以编程方式将Access(.mdb)文件读入R [英] Programmatically read Access (.mdb) files into R for both Windows and Mac
问题描述
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屋!