r - 为什么future::future() 不能与闪亮的dbAppendTable 一起使用?
问题描述
您可以使用 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
(无论是持久写入还是在内存中都不会创建表。)
解决方案
该DBI
包及其所有实现(如RSQLite
)确实使用不可导出的对象(基本上是内存指针),请参阅:
https://cran.r-project.org/web/packages/future/vignettes/future-4-non-exportable-objects.html
当您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
推荐阅读
- go - shell提示时自动输入定义的密码?
- perl - Windows 10 64bit 上的草莓 Perl Firebird 驱动程序和模块
- numpy - Numpy 索引在大型矩阵上需要几分钟
- pandas - 尝试在 python 中解析日期时出错
- c# - EF Core 3.0 替换 IMutableIndex.Npgsql() 方法
- python - 如何抓取仅在登录时显示的课程?
- fullcalendar - fullcalendar nextDayThreshold 不起作用。'00:00:00' 显示的时间少了一天
- reactjs - React 挂钩如何从子 Form.Control 设置对 InputGroup 的关注
- python - 有没有办法在不安装其他任何东西的情况下从音频文件中删除/编辑名为“标签”的元数据条目?
- python - 如何在执行任何语句之前调用连接方法