为什么future::future()不能与数据库中的dbAppendTable一起工作?
您可以使用future()来处理其副作用,例如写入文件:为什么future::future()不能与数据库中的dbAppendTable一起工作?,r,shiny,promise,future,R,Shiny,Promise,Future,您可以使用future()来处理其副作用,例如写入文件: library(promises) library(future) plan(multiprocess) future({write.csv(mtcars,"mtcars.csv")}) 但您不能使用数据库调用: library(RSQLite) library(promises) library(future) plan(multiprocess) con <- dbConnect(RSQLite::SQLite(), ":me
library(promises)
library(future)
plan(multiprocess)
future({write.csv(mtcars,"mtcars.csv")})
但您不能使用数据库调用:
library(RSQLite)
library(promises)
library(future)
plan(multiprocess)
con <- dbConnect(RSQLite::SQLite(), ":memory:")
future({
dbCreateTable(con, "iris", iris)
})
dbReadTable(con, "iris") # gives error
库(RSQLite)
图书馆(承诺)
图书馆(未来)
计划(多进程)
con我可能错了,但我怀疑这两个con
是不一样的,所以我猜未来就像是宿醉中的曼谷:未来内部发生的事情留在未来内部。可以说,您的con
是通过值(而不是通过引用)进行评估的,因此该表不会写入原始con
。考虑下面的代码:
库(未来)
x我可能错了,但我怀疑这两个con
是不一样的,所以我猜未来就像是宿醉中的曼谷:未来内部发生的事情留在未来内部。可以说,您的con
是通过值(而不是通过引用)进行评估的,因此该表不会写入原始con
。考虑下面的代码:
库(未来)
DBI
包及其所有实现(如RSQLite
)确实使用不可导出对象(基本上是内存指针),请参见:
当您像这样配置futures
时,可以看到一条错误消息:
options(future.globals.onReference = "error")
# ... your code goes here
# Error in FALSE :
# Detected a non-exportable reference (‘externalptr’) in one of the globals (‘con’ of class ‘SQLiteConnection’) used in the future expression
# Timing stopped at: 0.028 0 0.028
DBI
包及其所有实现(如RSQLite
)都使用不可导出对象(基本上是内存指针),请参见:
当您像这样配置futures
时,可以看到一条错误消息:
options(future.globals.onReference = "error")
# ... your code goes here
# Error in FALSE :
# Detected a non-exportable reference (‘externalptr’) in one of the globals (‘con’ of class ‘SQLiteConnection’) used in the future expression
# Timing stopped at: 0.028 0 0.028
当将未来与数据库连接一起使用时,您必须在未来内部创建(并可能关闭)连接:
库(RSQLite)
图书馆(承诺)
图书馆(未来)
计划(多进程)
未来({
con当将futures与数据库连接一起使用时,您必须在future内部创建(并可能关闭)连接:
库(RSQLite)
图书馆(承诺)
图书馆(未来)
计划(多进程)
未来({
骗局