diff --git a/DESCRIPTION b/DESCRIPTION index 07daf1a..6a2cac4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ChemotaxisDashboard Title: Chemotaxis dashboard -Version: 0.1 +Version: 0.1.1 Authors@R: c(person('Randy', 'Johnson', email = 'Randall.Johnson@nih.gov', role = c('cre','aut'))) Description: Dashboard for exploring chemotaxis data. diff --git a/NAMESPACE b/NAMESPACE index 762231e..7aa9e69 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -10,6 +10,7 @@ export(qc_cardsUI) export(qc_server) export(qc_sidebarUI) import(rlang) +importFrom(DBI,dbAppendTable) importFrom(DBI,dbConnect) importFrom(DBI,dbDisconnect) importFrom(DBI,dbGetQuery) diff --git a/R/initialize.R b/R/initialize.R index 3cc6f95..6898146 100644 --- a/R/initialize.R +++ b/R/initialize.R @@ -1,7 +1,7 @@ # initialize.R #' dbinit -#' Set up database and infrastructure needed to run the Chemotaxis-Dashboard +#' Set up database and infrastructure needed to run the Chemotaxis-Dashboard. If the database already exists and data is not empty, this will append the information in data to the database. #' #' @param db_path Character value specifying the path to the file where the database should be initialized. #' @param data List of data.frames to initialize or add to the database. Internal test data will be used if `data` is NULL. @@ -36,35 +36,67 @@ dbinit <- function(db_path, data = NULL) # add data.frames if(!'users' %in% tabs & !is.null(data$users)) + { dbWriteTable(con, "users", data$users) + }else if(!is.null(data$users)){ + dbAppendTable(con, "users", data$users) + } if(!'access' %in% tabs & !is.null(data$access)) + { dbWriteTable(con, "access", data$access) + }else if(!is.null(data$access)){ + dbAppendTable(con, "access", data$access) + } if(!'expSummary' %in% tabs & !is.null(data$expSummary)) + { dbWriteTable(con, "expSummary", data$expSummary) + }else if(!is.null(data$expSummary)){ + dbAppendTable(con, "expSummary", data$expSummary) + } if(!'expStats' %in% tabs & !is.null(data$expStats)) + { dbWriteTable(con, "expStats", data$expStats) + }else if(!is.null(data$expStats)){ + dbAppendTable(con, "expStats", data$expStats) + } if(!'chanSummary' %in% tabs & !is.null(data$chanSummary)) + { dbWriteTable(con, "chanSummary", data$chanSummary) - + }else if(!is.null(data$chanSummary)){ + dbAppendTable(con, "chanSummary", data$chanSummary) + } + if(!'chanRaw' %in% tabs & !is.null(data$chanRaw)) + { dbWriteTable(con, "chanRaw", data$chanRaw) + }else if(!is.null(data$chanRaw)){ + dbAppendTable(con, "chanRaw", data$chanRaw) + } if(!'trackSummary' %in% tabs & !is.null(data$trackSummary)) + { dbWriteTable(con, "trackSummary", data$trackSummary) + }else if(!is.null(data$trackSummary)){ + dbAppendTable(con, "trackSummary", data$trackSummary) + } if(!'trackRaw' %in% tabs & !is.null(data$trackRaw)) + { dbWriteTable(con, "trackRaw", data$trackRaw) + }else{ + dbAppendTable(con, "trackRaw", data$trackRaw) + } dbDisconnect(con) } diff --git a/data-raw/process_raw_data.R b/data-raw/process_raw_data.R index 5141d51..e0f186d 100644 --- a/data-raw/process_raw_data.R +++ b/data-raw/process_raw_data.R @@ -42,9 +42,14 @@ all_experiments <- all_experiments[!all_experiments %in% done] # process experiments that haven't been processed yet -processed_data <- process_experiments(all_experiments, - source_dir = file.path(root, 'data-raw', 'results_csv'), - results_dir = file.path(root, '.data'), - seed = 923847) +if(length(all_experiments) > 0) +{ + processed_data <- process_experiments(all_experiments, + source_dir = file.path(root, 'data-raw', 'results_csv'), + results_dir = file.path(root, '.data'), + seed = 923847) + + dbinit(db_path, processed_data) +} parallel::stopCluster(parallel::getDefaultCluster()) diff --git a/man/dbinit.Rd b/man/dbinit.Rd index 185db80..c5731d9 100644 --- a/man/dbinit.Rd +++ b/man/dbinit.Rd @@ -3,7 +3,7 @@ \name{dbinit} \alias{dbinit} \title{dbinit -Set up database and infrastructure needed to run the Chemotaxis-Dashboard} +Set up database and infrastructure needed to run the Chemotaxis-Dashboard. If the database already exists and data is not empty, this will append the information in data to the database.} \usage{ dbinit(db_path, data = NULL) } @@ -17,7 +17,7 @@ Something - use this to sniff for existing DB information? } \description{ dbinit -Set up database and infrastructure needed to run the Chemotaxis-Dashboard +Set up database and infrastructure needed to run the Chemotaxis-Dashboard. If the database already exists and data is not empty, this will append the information in data to the database. } \details{ The data.frames expected in data are `users`, `access`, `expSummary`, `expStats`, `chanSummary`, `chanRaw`,