在操作到第三步的时候,我这边报了一个错,报错信息:
An error occurred:
Error: Cannot pass NA to dbQuoteIdentifier()
Finally done!
An error occurred:
Error in dbExistsTable(conn, name): 不是所有的length(name) == 1都是TRUE
code如下:
> path = "D:\\GroupP" #这里替换成自己的路径
> LenPath = nchar(path)
> filenames <- list.files(path , pattern="*.csv", full.names=TRUE)
> ldf <- lapply(filenames, read.csv)
> res <- lapply(ldf, summary)
> names(res) <- substr(filenames,LenPath+1, LenPath + 3) #这里要根据自己的文件名改变长度
> library(DBI)
> library(odbc)
> con <- dbConnect(odbc::odbc(),
Driver = "SQL Server",
Server = "shenjing", #这里替换成自己的Server名字
Database = "Group_Bussiness", #这里替换成自己的DataBase名字
Trusted_Connection = "True")
> for(i in 1:length(ldf)){
tryCatch(
data <-dbWriteTable(con, names(res)[i], data.frame(ldf[i]))
,
error = function(e){
message("An error occurred:\n", e)
},
warning = function(w){
message("A warning occured:\n", w)
},
finally = {
message("Finally done!")
})
}
基础数据路径和文件名如下: