R语言在编程过程中,遇到一个问题,在使用RODBC过程中提示和报错信息:
R version 3.4.2 (2017-09-28) -- "Short Summer"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
[Workspace loaded from ~/.RData]
> library(RODBC)
> XlsChannel <- odbcConnectExcel("test.xlsx")
Error in odbcConnectExcel("test.xlsx") :
odbcConnectExcel is only usable with 32-bit Windows
>
类似问题可能需要我们切换R语言运行环境,下面介绍Rstudio切换运行环境。
首先打开Rstudio,找到工具(options)选项。如下图所示。
找到Global Options,如下图所示。
在General选项中找到R version,不需要切换标签,如下图所示。
重新启动编辑器Rstudio即可,错误一般可以消失。
下面介绍所遇到第二个问题。
> library(RODBC)
> channel<-odbcConnectExcel("test.xlsx")
Warning messages:
1: In odbcDriverConnect(con, tabQuote = c("[", "]"), ...) :
[RODBC] ERROR: state 42000, code -1809, message [Microsoft][ODBC Excel 驱动程序] 不能更新。数据库或对象为只读。
2: In odbcDriverConnect(con, tabQuote = c("[", "]"), ...) :
ODBC connection failed
先尝试文件指定绝对路径。
> channel<-odbcConnectExcel("C:\\Documents\\R\\test.xlsx")
Warning messages:
1: In odbcDriverConnect(con, tabQuote = c("[", "]"), ...) :
[RODBC] ERROR: state HY000, code -5015, message [Microsoft][ODBC Excel 驱动程序] 外部表不是预期的格式。
2: In odbcDriverConnect(con, tabQuote = c("[", "]"), ...) :
ODBC connection failed
仔细检查代码,发现问题所在,修改后代码如下:
channel<- odbcConnectExcel2007("C:\\Documents\\R\\test.xlsx")