发布自动CSV导入到RSQLite DB

时间:2017-12-03 02:31:02

标签: sql r sqlite

我试图自动将CSV文件写入RSQLite DB。

我是通过索引csvFiles来做到这一点的,dbWriteTable()是存储在环境中的data.frame变量列表。

我似乎无法弄清楚为什么我的name代码在我手动输入时完全正常,但在我尝试索引value### CREATE DB ### mydb <- dbConnect(RSQLite::SQLite(),"") # FOR LOOP TO BATCH IMPORT DATA INTO DATABASE for (i in 1:length(csvFiles)) { dbWriteTable(mydb,name = csvFiles[i], value = csvFiles[i], overwrite=T) i=i+1 } # EXAMPLE CODE THAT SUCCESSFULLY MANUAL IMPORTS INTO mydb dbWriteTable(mydb,"DEPARTMENT",DEPARTMENT) 字段时则无法正常工作。

"Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
  cannot open file 'DEPARTMENT': No such file or directory

# note that 'DEPARTMENT' is the value of csvFiles[1]

当我运行上面的for循环时,我发出了这个错误:

dput

这里是csvFiles的{​​{1}}输出:

c("DEPARTMENT", "EMPLOYEE_PHONE", "PRODUCT", "EMPLOYEE", "SALES_ORDER_LINE", 
"SALES_ORDER", "CUSTOMER", "INVOICES", "STOCK_TOTAL")

我已经研究过这个错误,它似乎与我的工作目录有关;但是,我真的不明白要改变什么,因为我甚至没有尝试从我的计算机上操作文件,只是数据框架已经存在于我的环境中。

请帮忙!

1 个答案:

答案 0 :(得分:0)

只需在{em> value 参数中使用Private WithEvents olRemind As Outlook.Reminders Private Sub Application_Reminder(ByVal Item As Object) Set olRemind = Outlook.Reminders If Item.MessageClass <> "IPM.Task" Then Exit Sub End If If Item.Categories <> "Online" Then Exit Sub End If SetOnline Timed_box (1) Pause 30 SetOffline Item.MarkComplete Set olRemind = Outlook.Reminders For Each objRem In olRemind If Item.Categories = "Online" Then If objRem.IsVisible Then objRem.Dismiss Cancel = True End If Exit For End If Next objRem End Sub 'Categorize Sent Items 'Place in ThisOutlookSession Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) If TypeOf Item Is Outlook.MailItem And Len(Item.Categories) = 0 Then Set Item = Application.ActiveInspector.CurrentItem Item.ShowCategoriesDialog End If End Sub ,因为在预期数据框对象时传递字符串值。请注意,您的手动版本没有为引用Set Item = Application.ActiveInspector.CurrentItem

get()

或者,考虑使用DEPARTMENT构建一个命名数据框列表,并在列表名称和带# FOR LOOP TO BATCH IMPORT DATA INTO DATABASE for (i in seq_along(csvFiles)) { dbWriteTable(mydb,name = csvFiles[i], value = get(csvFiles[i]), overwrite=T) } 的df元素之间逐元素地循环:

mget