How to read data from Microsoft Access .accdb database files into R?

前端 未结 8 1121
夕颜
夕颜 2020-12-16 14:05

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

相关标签:
8条回答
  • 2020-12-16 14:13

    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.

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

    0 讨论(0)
  • 2020-12-16 14:15

    The best method that worked for me

    #Package
    library(RODBC)
    
    #Defining the path
    datab<-file.path("Main_File.accdb")
    channel<-odbcConnectAccess2007(datab)
    
    #reading the individual files inside the Main
    table<-sqlFetch(Channel,"File_1")
    

    This will fetch data from the "File_1" inside the Main_File.

    But the above code did not support the UTF encoding.

    0 讨论(0)
  • 2020-12-16 14:18

    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.

    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.

    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.

    0 讨论(0)
  • 2020-12-16 14:26
    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
    
    0 讨论(0)
  • 2020-12-16 14:28

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

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

    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
    
    0 讨论(0)
  • 2020-12-16 14:28

    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.

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

    0 讨论(0)
提交回复
热议问题