在 MacOS 上集成 Microsoft Access 和 R

Integrating Microsoft Access and R on MacOS

提问人:Obleo Demandre 提问时间:11/6/2023 最后编辑:Obleo Demandre 更新时间:11/6/2023 访问量:43

问:

我正在处理一个项目,我们希望直接从 Microsoft Access 文件中提取数据。我想出了一种方法让它在 Windows 上运行,但在 Mac 上遇到了问题(它说我没有合适的驱动程序)。我知道 Mac 不支持 Access,但我想知道是否还有一种方法可以在不打开 Access 文件本身的情况下直接提取数据。

成功的 Windows 代码(仅从 Access 数据库中提取随机表)

#install.packages("odbc") 
#install.packages("RODBC")
#install.packages("tidyverse")

library(odbc)
library(RODBC)
library(tidyverse)

unique(odbc::odbcListDrivers()[[1]]) #See drivers already installed on computer
#[2] "Microsoft Access Driver (*.mdb, *.accdb)"  We have this as one of the drivers.

#Now provide the path for the database.
db <- "C:\\Users\\Molly\\Desktop\\Obleo Docs\\Data\\NPRI_20230330.accdb"


#Use RODB functions to connect db to R
#I am using the Access 2007 function, because this is the version I have
con <- RODBC::odbcConnectAccess2007(db)
print(con)

#Grab a table from the access database
df_Company <- RODBC::sqlFetch(con,"Company",rownames= FALSE)
#head(df_Company)
#View(df_Company)
#The upload worked

Mac 的不成功代码

library(odbc)
library(RODBC)
library(tidyverse)

unique(odbc::odbcListDrivers()[[1]]) #See drivers already installed on computer
#On a mac I got character(0). We don't have the correct drivers at this point
r macOS MS-Access ODBC RODBC

评论

0赞 June7 11/6/2023
这对 github.com/ethoinformatics/r-database-connections/blob/master/ 有帮助吗?
0赞 Erik A 11/7/2023
6 月 7 日链接的资源是一条路。使用 iODBC 构建 mdbtools 后,您也应该能够使用 DBI。另一种方法是 UCanAccess + RJDBC。

答: 暂无答案