#ifdef unix
# MySQL
channel <- odbcConnect("test", uid="ripley", pwd="secret")
# PostgreSQL
channel <- odbcConnect("pg", uid="ripley", pwd="secret", case="postgresql")
#endif
#ifdef windows
# interactive specification
channel <- odbcDriverConnect("")
# MySQL on Windows -- MySQL maps to lower case on Windows only
channel <- odbcConnect("testdb", uid="ripley", case="tolower")
# Access
channel <- odbcConnect("testacc") # if this was set up as a DSN
channel2 <- odbcConnectAccess("test.mdb", uid="ripley")
# Excel
channel <- odbcConnect("bdr.xls") # if this was set up as a DSN
channel2 <-
odbcDriverConnect("DRIVER=Microsoft Excel Driver (*.xls);DBQ=C:\bdr\hills.xls")
channel3 <- odbcConnectExcel("bdr.xls")
#endif
# re-connection
odbcCloseAll()
channel <- odbcReConnect(channel) # must re-assign as the data may well change
Run the code above in your browser using DataLab