如何从Microsoft Access .accdb数据库文件中读取数据到R?

时间:2021-02-12 15:20:55

The RODBC documentation suggests it is possible, but I am not sure how to read data from a Microsoft Access (the new .accdb format) file with this package into R (on Debian GNU/Linux). The vignette talks about drivers, but I do not quite understand how I can see which drivers are installed, and in particular, if I have a driver installed for me to access those .accdb files.

RODBC文档表明它是可能的,但我不确定如何将带有此软件包的Microsoft Access(新的.accdb格式)文件中的数据读入R(在Debian GNU / Linux上)。小插图讨论驱动程序,但我不太明白我如何看到安装了哪些驱动程序,特别是,如果我安装了驱动程序来访问这些.accdb文件。

What code do you use to read data from .accdb files? And please indicate what platform you are on and if you had to install a special driver.

您使用什么代码从.accdb文件中读取数据?请说明您所使用的平台以及是否必须安装特殊驱动程序。

7 个解决方案

#1


4  

The title of the page you linked, RODBC: ODBC Database Access, may be misleading. Access doesn't mean MS Access; in that title access means connectivity. RODBC is an ODBC manager for R. It serves as the mediator to provide communication between R and the ODBC driver for your target database. So for GNU/Linux, you would still need an ODBC driver for MS Access database files ... RODBC doesn't provide one.

您链接的页面标题RODBC:ODBC数据库访问可能会产生误导。访问并不意味着MS Access;在该标题中,访问意味着连接。 RODBC是R的ODBC管理器。它充当调解器,为目标数据库提供R和ODBC驱动程序之间的通信。因此对于GNU / Linux,您仍然需要一个用于MS Access数据库文件的ODBC驱动程序...... RODBC不提供。

However, I don't know of any free (as in freedom and/or beer) MS Access ODBC drivers for Linux. Easysoft sells one, but it's not cheap. There may be offerings from other vendors, too; I haven't looked.

但是,我不知道任何免费的(如在*和/或啤酒中)用于Linux的MS Access ODBC驱动程序。 Easysoft出售一个,但它并不便宜。也可能有来自其他供应商的产品;我没看过。

It might be easier to use a Windows machine to export your ACCDB to a format R can use. Or run R on Windows instead of Linux.

使用Windows机器将ACCDB导出为R可以使用的格式可能更容易。或者在Windows上运行R而不是Linux。

#2


7  

To import a post-2007 Microsoft Access file (.accdb) into R, you can use the RODBC package.

若要将2007年后的Microsoft Access文件(.accdb)导入R,您可以使用RODBC包。

For an .accdb file called "foo.accdb" with the following tables, "bar" and "bin", stored on the desktop of John Doe's computer:

对于名为“foo.accdb”的.accdb文件,其中包含以下表格,“bar”和“bin”,存储在John Doe计算机的桌面上:

library(RODBC)    #loads the RODBC package
dta <- odbcConnectAccess2007("C:/Users/JohnDoe/Desktop/foo.accdb")   #specifies the file path
df1 <- sqlFetch(dta, "bar")   #loads the table called 'bar' in the original Access file
df2 <- sqlFetch(dta, "bin")   #loads the table called 'bin' in the original Access file

#3


3  

ODBC is a bit of 'plug and pray' system connecting different bricks.

ODBC是一个连接不同砖块的“即插即用”系统。

RODBC allow you to get something from an ODBC provider into R. What you still need is the (for lack of a better word) ODBC-exporting driver of the database system in question. Which you need on your OS --- so I think with the Access-into-Linux combination you are without luck. Windows-only.

RODBC允许您从ODBC提供程序中获取某些内容。您仍需要的是(缺少更好的单词)数据库系统的ODBC导出驱动程序。您在操作系统上需要哪些 - 所以我认为使用Access-into-Linux组合你没有运气。仅Windows。

People have managed to access SQL Server using FreeTDS drivers (for the TDS protocol underlying Sybase and via an early license also MS-SQL) but it is usualluy a fight to get it going.

人们已经设法使用FreeTDS驱动程序访问SQL Server(对于Sybase底层的TDS协议以及早期的许可证也是MS-SQL),但通常情况下这是一个很难实现的目标。

#4


3  

You'll need the drivers to connect Access to the ODBC interface. These should be on your system if you have Access installed. If not, download the Access Database Engine from Microsoft. Then create your data connection in ODBC (You may need to run the 32-bit c:\windows\sysWOW64\odbcad32.exe if running 64-bit Windows). Note that this method doesn't work on GNU/Linux. The runtimes are Windows only, as mentioned by @HansUp below.

您需要驱动程序将Access连接到ODBC接口。如果您安装了Access,这些应该在您的系统上。如果没有,请从Microsoft下载Access数据库引擎。然后在ODBC中创建数据连接(如果运行64位Windows,则可能需要运行32位c:\ windows \ sysWOW64 \ odbcad32.exe)。请注意,此方法不适用于GNU / Linux。运行时仅限Windows,如下面的@HansUp所述。

As for code, you'll probably start with odbcConnect(dsn, uid = "", pwd = "", ...), and the documentation can help with the details.

至于代码,您可能会从odbcConnect(dsn,uid =“”,pwd =“”,...)开始,文档可以帮助您了解详细信息。

#5


2  

> library(RODBC)
> db<-file.path("student.accdb")
> channel<-odbcConnectAccess2007(db)
> data<-sqlFetch(channel,"stud")
> data
  ID  Name M1 M2 M3 M4 M5 Result
1  7 Radha 85 65 92 50 62   Pass
2  8  Reka 75 85 96 75 85   Pass

#6


1  

An alternative to directly accessing it might be to facilitate the data export from MS Access. At least the most recent MS Access allows to save the various export steps. One can then simply run the export of various queries / tables fairly quickly.

直接访问它的替代方法可能是促进从MS Access导出数据。至少最新的MS Access允许保存各种导出步骤。然后,可以非常快速地运行各种查询/表的导出。

I know this does not answer the question, but might be a workaround if you do not get RODBC to run.

我知道这不能回答这个问题,但如果你没有让RODBC运行,可能会解决这个问题。

#7


1  

The best method that worked for me

对我有用的最佳方法

library(RODBC)
datab<-file.path("Enroll.accdb")
channel<-odbcConnectAccess2007(datab)
table<-sqlFetch(channel,"2011")

This will fetch data from the "2011" inside the enroll file. But the UTF encoding doesn't work with this.

这将从注册文件中的“2011”中获取数据。但UTF编码不适用于此。

#1


4  

The title of the page you linked, RODBC: ODBC Database Access, may be misleading. Access doesn't mean MS Access; in that title access means connectivity. RODBC is an ODBC manager for R. It serves as the mediator to provide communication between R and the ODBC driver for your target database. So for GNU/Linux, you would still need an ODBC driver for MS Access database files ... RODBC doesn't provide one.

您链接的页面标题RODBC:ODBC数据库访问可能会产生误导。访问并不意味着MS Access;在该标题中,访问意味着连接。 RODBC是R的ODBC管理器。它充当调解器,为目标数据库提供R和ODBC驱动程序之间的通信。因此对于GNU / Linux,您仍然需要一个用于MS Access数据库文件的ODBC驱动程序...... RODBC不提供。

However, I don't know of any free (as in freedom and/or beer) MS Access ODBC drivers for Linux. Easysoft sells one, but it's not cheap. There may be offerings from other vendors, too; I haven't looked.

但是,我不知道任何免费的(如在*和/或啤酒中)用于Linux的MS Access ODBC驱动程序。 Easysoft出售一个,但它并不便宜。也可能有来自其他供应商的产品;我没看过。

It might be easier to use a Windows machine to export your ACCDB to a format R can use. Or run R on Windows instead of Linux.

使用Windows机器将ACCDB导出为R可以使用的格式可能更容易。或者在Windows上运行R而不是Linux。

#2


7  

To import a post-2007 Microsoft Access file (.accdb) into R, you can use the RODBC package.

若要将2007年后的Microsoft Access文件(.accdb)导入R,您可以使用RODBC包。

For an .accdb file called "foo.accdb" with the following tables, "bar" and "bin", stored on the desktop of John Doe's computer:

对于名为“foo.accdb”的.accdb文件,其中包含以下表格,“bar”和“bin”,存储在John Doe计算机的桌面上:

library(RODBC)    #loads the RODBC package
dta <- odbcConnectAccess2007("C:/Users/JohnDoe/Desktop/foo.accdb")   #specifies the file path
df1 <- sqlFetch(dta, "bar")   #loads the table called 'bar' in the original Access file
df2 <- sqlFetch(dta, "bin")   #loads the table called 'bin' in the original Access file

#3


3  

ODBC is a bit of 'plug and pray' system connecting different bricks.

ODBC是一个连接不同砖块的“即插即用”系统。

RODBC allow you to get something from an ODBC provider into R. What you still need is the (for lack of a better word) ODBC-exporting driver of the database system in question. Which you need on your OS --- so I think with the Access-into-Linux combination you are without luck. Windows-only.

RODBC允许您从ODBC提供程序中获取某些内容。您仍需要的是(缺少更好的单词)数据库系统的ODBC导出驱动程序。您在操作系统上需要哪些 - 所以我认为使用Access-into-Linux组合你没有运气。仅Windows。

People have managed to access SQL Server using FreeTDS drivers (for the TDS protocol underlying Sybase and via an early license also MS-SQL) but it is usualluy a fight to get it going.

人们已经设法使用FreeTDS驱动程序访问SQL Server(对于Sybase底层的TDS协议以及早期的许可证也是MS-SQL),但通常情况下这是一个很难实现的目标。

#4


3  

You'll need the drivers to connect Access to the ODBC interface. These should be on your system if you have Access installed. If not, download the Access Database Engine from Microsoft. Then create your data connection in ODBC (You may need to run the 32-bit c:\windows\sysWOW64\odbcad32.exe if running 64-bit Windows). Note that this method doesn't work on GNU/Linux. The runtimes are Windows only, as mentioned by @HansUp below.

您需要驱动程序将Access连接到ODBC接口。如果您安装了Access,这些应该在您的系统上。如果没有,请从Microsoft下载Access数据库引擎。然后在ODBC中创建数据连接(如果运行64位Windows,则可能需要运行32位c:\ windows \ sysWOW64 \ odbcad32.exe)。请注意,此方法不适用于GNU / Linux。运行时仅限Windows,如下面的@HansUp所述。

As for code, you'll probably start with odbcConnect(dsn, uid = "", pwd = "", ...), and the documentation can help with the details.

至于代码,您可能会从odbcConnect(dsn,uid =“”,pwd =“”,...)开始,文档可以帮助您了解详细信息。

#5


2  

> library(RODBC)
> db<-file.path("student.accdb")
> channel<-odbcConnectAccess2007(db)
> data<-sqlFetch(channel,"stud")
> data
  ID  Name M1 M2 M3 M4 M5 Result
1  7 Radha 85 65 92 50 62   Pass
2  8  Reka 75 85 96 75 85   Pass

#6


1  

An alternative to directly accessing it might be to facilitate the data export from MS Access. At least the most recent MS Access allows to save the various export steps. One can then simply run the export of various queries / tables fairly quickly.

直接访问它的替代方法可能是促进从MS Access导出数据。至少最新的MS Access允许保存各种导出步骤。然后,可以非常快速地运行各种查询/表的导出。

I know this does not answer the question, but might be a workaround if you do not get RODBC to run.

我知道这不能回答这个问题,但如果你没有让RODBC运行,可能会解决这个问题。

#7


1  

The best method that worked for me

对我有用的最佳方法

library(RODBC)
datab<-file.path("Enroll.accdb")
channel<-odbcConnectAccess2007(datab)
table<-sqlFetch(channel,"2011")

This will fetch data from the "2011" inside the enroll file. But the UTF encoding doesn't work with this.

这将从注册文件中的“2011”中获取数据。但UTF编码不适用于此。