[英]Copy_to in R results in dates being converted to numeric columns
I am attempting to create a small, training database for a package that I am writing.我正在尝试为我正在编写的包创建一个小型的训练数据库。 I am using the following code to create the database:
我正在使用以下代码创建数据库:
library(tidyverse)
library(DBI)
dat <- data.frame(name = rep("Clyde", 100),
DOB = sample(x = seq(as.POSIXct('1970/01/01'), as.POSIXct('1995/01/01'), by="day"),
size = 100, replace = T))
# Example using schemas with SQLite
train_con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
## create tables in primary db
copy_to(dest = train_con, df = dat, name = "client_list", temporary = FALSE)
The above portion works fine.以上部分工作正常。 However, when I attempt to pull data from the database, I see that all dates have been converted to numeric.
但是,当我尝试从数据库中提取数据时,我看到所有日期都已转换为数字。
train_con %>% tbl("client_list")
Can anybody tell me how to fix this?谁能告诉我如何解决这个问题? Thanks!
谢谢!
SQLite does not have a datetime type. SQLite 没有日期时间类型。 In the absence of such a type POSIXct objects are sent to the database as seconds since the UNIX Epoch and SQLite does not know that they are intended to represent date times.
由于 UNIX Epoch 和 SQLite 不知道它们用于表示日期时间,因此没有这种类型的 POSIXct 对象将作为秒发送到数据库。
Either convert such columns yourself after you read them back into R or else use a different database.在您将这些列读回 R 后自己转换它们,或者使用不同的数据库。 Nearly all databases except SQLite support this.
除了 SQLite 之外,几乎所有数据库都支持这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.