Skip to content

Commit

Permalink
convert dates to numbers when loading data to sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
ablack3 committed Jul 27, 2023
1 parent de2f359 commit 8686477
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions R/EunomiaData.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ extractLoadData <- function(from, to, dbms = "sqlite", verbose = interactive())
# CDM table and column names should be lowercase: https://github.com/OHDSI/CommonDataModel/issues/509#issuecomment-1315754238
names(tableData) <- tolower(names(tableData))
tableName <- tools::file_path_sans_ext(tolower(dataFiles[i]))

if (dbms == "sqlite") {
# Convert dates and datetime to UNIX timestamp for sqlite
for (i in seq_len(ncol(tableData))) {
column <- tableData[[i]]
if (inherits(column, "Date")) {
tableData[, i] <- as.numeric(as.POSIXct(as.character(column), origin = "1970-01-01", tz = "GMT"))
}
if (inherits(column, "POSIXct")) {
tableData[, i] <- as.numeric(as.POSIXct(column, origin = "1970-01-01", tz = "GMT"))
}
}
}

DBI::dbWriteTable(conn = connection, name = tableName, value = tableData)
if (verbose) {
cli::cat_bullet(tableName, bullet = 1)
Expand Down

0 comments on commit 8686477

Please sign in to comment.