RODBC and Access - Loading data

前端 未结 2 1325
栀梦
栀梦 2021-01-14 09:16

I am trying to load some data into R from an Access database. All of the instructions I can find say to use odbcConnectAccess(\"file.mdb\") but I cannot seem to load this fu

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-14 10:07

    If you're using on a Mac, I've found success using Actual Technologies drivers to connect to Access databases. If you've already set up the ODBC connection, using ODBC Source Administrator on Windows or ODBC Administrator on a Mac, the rest is fairly straightforward.

    library(RODBC)
    # Open up channel to database supplying name of ODBC connection and user name
    
    data.ch<-odbcConnect("ODBC_Connection_name",uid="user_name") 
    

    There is also an option to supply a password in odbcConnect, but I've set up the connection with the password included.

    sqlTables(data.ch) # Query the connection for all tables
    
    # Fetch all data from a table called "Table_name" or use standard SQL statements
     df<-sqlFetch(data.ch,"Table_name") 
    

提交回复
热议问题