Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么future::future()不能与数据库中的dbAppendTable一起工作?_R_Shiny_Promise_Future - Fatal编程技术网

为什么future::future()不能与数据库中的dbAppendTable一起工作?

为什么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

您可以使用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(), ":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)
图书馆(承诺)
图书馆(未来)
计划(多进程)
未来({
骗局