From d03999c69926b419948eda9a80c523acac642135 Mon Sep 17 00:00:00 2001 From: Chowdhury Date: Mon, 7 Jun 2021 18:10:34 -0400 Subject: [PATCH] Get date_time from file structure if METADATA is missing and emit a warning --- R/experiment-info.R | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/R/experiment-info.R b/R/experiment-info.R index b410e3f..b2cd95f 100644 --- a/R/experiment-info.R +++ b/R/experiment-info.R @@ -16,9 +16,18 @@ experiment_info <- function(FILE){ {metadata <- RSQLite::dbGetQuery(con, "SELECT * FROM METADATA")}, finally={RSQLite::dbDisconnect(con)}) - v <- as.list(metadata$value) - names(v) <- metadata$field - #fixme explicitly GMT - v$date_time <- as.POSIXct(as.integer(v$date_time),origin="1970-01-01",tz = "GMT") + if (nrow(metadata) == 0) { + warning(paste0("sqlite3 file ", FILE, "has an empty METADATA table")) + v <- list() + # this assumes the folder the dbfile lives in is the datetime when the experiment started, which should be true in a normal case + # the format of the datetime is YYYY-MM-DD_HH-MM-SS + date_time_str <- rev(unlist(strsplit(dirname(FILE), split ="/")))[1] + v$date_time <- as.POSIXct(date_time_str, tz="GMT", format="%Y-%m-%d_%H-%M-%S") + } else { + v <- as.list(metadata$value) + names(v) <- metadata$field + #fixme explicitly GMT + v$date_time <- as.POSIXct(as.integer(v$date_time),origin="1970-01-01",tz = "GMT") + } return(v) }