admin管理员组

文章数量:1122846

I'm a student of Data Science, and I'm working in a project to visualize a database of Spanish reservoirs; but I'm getting this error:

# package installations if required:
if(!require("tidyverse")) install.packages("tidyverse")
if(!require("janitor")) install.packages("janitor")
if(!require("patchwork")) install.packages("patchwork")
if(!require("RODBC")) install.packages("RODBC")

# load the packages
library(tidyverse)
library(readxl)
library(janitor)
library(patchwork)
library(RODBC)

# URL of the database
url <- ".zip"

# download
tempf <- tempfile() # temp file
download.file(url, tempf) 
unzip(tempf)

# open the connection with mdb
conn <- odbcConnectAccess2007("BD-Embalses.mdb")

I installed everything on my system (Arch linux), but I can't make the connection to the database for some reason (it says that the function could not be found). Everything is in Spanish, I'm just translating it into English.

I'm a student of Data Science, and I'm working in a project to visualize a database of Spanish reservoirs; but I'm getting this error:

# package installations if required:
if(!require("tidyverse")) install.packages("tidyverse")
if(!require("janitor")) install.packages("janitor")
if(!require("patchwork")) install.packages("patchwork")
if(!require("RODBC")) install.packages("RODBC")

# load the packages
library(tidyverse)
library(readxl)
library(janitor)
library(patchwork)
library(RODBC)

# URL of the database
url <- "https://www.miteco.gob.es/content/dam/miteco/es/agua/temas/evaluacion-de-los-recursos-hidricos/boletin-hidrologico/Historico-de-embalses/BD-Embalses.zip"

# download
tempf <- tempfile() # temp file
download.file(url, tempf) 
unzip(tempf)

# open the connection with mdb
conn <- odbcConnectAccess2007("BD-Embalses.mdb")

I installed everything on my system (Arch linux), but I can't make the connection to the database for some reason (it says that the function could not be found). Everything is in Spanish, I'm just translating it into English.

Share Improve this question asked Nov 22, 2024 at 14:33 AlbertoAlberto 255 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

As can be found in the win.R file of the RODBC package, odbcConnectAccess2007 is a Windows-exclusive function. It depends on an ODBC driver for MS Access being available, and these are only available for Windows.

This means you need to find an alternative way, e.g. using mdbtools with the ODBC driver and either DBI + odbc (recommended) or RODBC, mdbtools + Hmisc::mdb.get, or RJDBC + UCanAccess.

Side note, always download.file(url, tempf, mode = "wb") if you're downloading a non-text file. This would lead to errors further down the line.

本文标签: