diff --git a/DESCRIPTION b/DESCRIPTION index 4f58b78..a378a77 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -10,8 +10,7 @@ Authors@R: email = "v.vanhees@accelting.com")) License: Apache License version 2.0 | file LICENSE Imports: shiny, shinyFiles, GGIR, bslib, methods, jsonlite, DT, - magrittr, shinyjs, callr, hbGPS, hbGIS, actilifecounts, ActCR, - GGIRread, read.gt3x, readxl + magrittr, shinyjs, callr, hbGPS, hbGIS Remotes: habitus-eu/hbGPS, habitus-eu/hbGIS LazyData: true Suggests: testthat, covr, rmarkdown diff --git a/R/GGIRshiny.R b/R/GGIRshiny.R index 1de21dd..0948e27 100644 --- a/R/GGIRshiny.R +++ b/R/GGIRshiny.R @@ -4,36 +4,31 @@ #' @param outputdir Path to output directory #' @param sleepdiary Path to sleep diary #' @param configfile Configfile path -#' @param do.Counts Boolean to indicate whether BrondCounts should be derived #' @return no object is returned, only a new file is created in the output directory #' @import GGIR #' @importFrom utils write.table #' @export +#' -GGIRshiny = function(rawaccdir, outputdir, sleepdiary = c(), configfile = c(), - do.Counts = FALSE) { +GGIRshiny = function(rawaccdir, outputdir, sleepdiary = c(), configfile = c()) { if (length(sleepdiary) == 0) sleepdiary = c() if (length(configfile) == 0) configfile = c() + # create R script with the code to run the data analysis via a command line call # in this way turning off or restarting the app will not kill the data analysis fileConn <- file(paste0(outputdir, "/ggir_cmdline.R")) writeLines(c("#!/usr/bin/env Rscript", "args = commandArgs(trailingOnly = TRUE)", - "if (length(args) < 4) {", - "stop(\"At least four arguments are expected\", call. = FALSE)", + "if (length(args) < 3) {", + "stop(\"At least three arguments are expected\", call. = FALSE)", "}", - "if (length(args) == 5) {", + "if (length(args) == 4) {", "GGIR::GGIR(datadir = args[1], outputdir = args[2], ", - " do.neishabouricounts = as.logical(args[3]),", - "configfile = args[4], loglocation = args[5],", + "configfile = args[3], loglocation = args[4],", "do.parallel = TRUE)", "} else {", "GGIR::GGIR(datadir = args[1], outputdir = args[2], ", - " do.neishabouricounts = as.logical(args[3]),", - "configfile = args[4], do.parallel = TRUE)", - "}", - "if (as.logical(args[3]) == TRUE) {", - "HabitusGUI::Counts2csv(outputdir = paste0(args[2], \"/output_\", basename(args[1])), configfile = args[4])", + "configfile = args[3], do.parallel = TRUE)", "}"), fileConn) close(fileConn) @@ -49,7 +44,6 @@ GGIRshiny = function(rawaccdir, outputdir, sleepdiary = c(), configfile = c(), basecommand = paste0(outputdir, "/ggir_cmdline.R ", rawaccdir, " ", outputdir, " ", - do.Counts, " ", configfile, " ", sleepdiary) system2(command = "Rscript", args = basecommand, @@ -66,11 +60,9 @@ GGIRshiny = function(rawaccdir, outputdir, sleepdiary = c(), configfile = c(), basecommand = paste0("cd ", outputdir, " ; nohup Rscript ggir_cmdline.R ", rawaccdir, " ", outputdir, " ", - do.Counts, " ", configfile, " ", sleepdiary, " > ", outputdir, "/GGIR.log 2>&1 &") system2(command = "cd", args = gsub(pattern = "cd ", replacement = "", x = basecommand), stdout = "", stderr = "", wait = TRUE) } - } \ No newline at end of file diff --git a/R/myApp.R b/R/myApp.R index cf2ed0a..3678fb6 100644 --- a/R/myApp.R +++ b/R/myApp.R @@ -13,7 +13,8 @@ # pkgload::load_all("."); HabitusGUI::myApp(homedir="~/projects/fontys") # HabitusGUI::myApp(homedir="~/projects") # pkgload::load_all("."); myApp(homedir="D:/Dropbox/Work/sharedfolder/DATA/Habitus") -# myApp(homedir="D:/Dropbox/Work/sharedfolder/DATA/Habitus/GPSprocessing/NBBB2010") +# myApp(homedir="D:/Dropbox/Work/sharedfolder/DATA/Habitus/GPSprocessing") + # roxygen2::roxygenise() @@ -799,38 +800,29 @@ myApp <- function(homedir=getwd(), ...) { # Apply GGIR after button is pressed #======================================================================== runGGIR <- eventReactive(input$start_ggir, { - GGIRCounts_message = "" + GGIR_message = "" if ("GGIR" %in% input$tools) { - GGIRCounts_message = "" + GGIR_message = "" # Basic check before running function: - ready_to_run_ggirCounts = FALSE + ready_to_run_ggir = FALSE if (dir.exists(global$raw_acc_in)) { acc_files_available = length(dir(path = global$raw_acc_in, pattern = "csv|bin|gt3x|bin|cwa|wav", recursive = FALSE, full.names = FALSE)) > 0 if (acc_files_available == TRUE) { - ready_to_run_ggirCounts = TRUE + ready_to_run_ggir = TRUE } else { - GGIRCounts_message = paste0("No count files found in ", global$raw_acc_in) + GGIR_message = paste0("No files found in ", global$raw_acc_in) } } else { - GGIRCounts_message = paste0("Folder that is supposed to hold acceleration files does not exist: ", global$raw_acc_in) + GGIR_message = paste0("Folder that is supposed to hold acceleration files does not exist: ", global$raw_acc_in) } # Only run function when checks are met: - if (ready_to_run_ggirCounts == TRUE) { + if (ready_to_run_ggir == TRUE) { shinyjs::hide(id = "start_ggir") - # this line makes that if user is trying to use a config defined in a previous - # run, the data path is correctly defined - config = read.csv(as.character(configfileGGIR())) - config.Counts = config$value[which(config$argument == "do.neishabouricounts")] - if (as.logical(config.Counts) == TRUE) { - # if counts was not selected as a tool, but acc.metric was defined as - # NeishabouriCount, then turn do.Counts to TRUE - id_ggir = showNotification("GGIR and CountConverter in progress ...", type = "message", duration = NULL, closeButton = FALSE) - do.Counts = TRUE - } else { - id_ggir = showNotification("GGIR in progress ...", type = "message", duration = NULL, closeButton = FALSE) - do.Counts = FALSE - } + # this line makes that if user is trying to use a config defined in a previous + # run, the data path is correctly defined + config = read.csv(as.character(configfileGGIR())) + id_ggir = showNotification("GGIR in progress ...", type = "message", duration = NULL, closeButton = FALSE) if (file.exists(paste0(global$data_out, "/sleepdiary.csv"))) { # because this is not a global variable sleepdiaryfile_local = paste0(global$data_out, "/sleepdiary.csv") @@ -848,16 +840,15 @@ myApp <- function(homedir=getwd(), ...) { }) # Start GGIR x_ggir <- r_bg(func = function(GGIRshiny, rawaccdir, outputdir, - sleepdiary, configfile, do.Counts){ + sleepdiary, configfile){ GGIRshiny(rawaccdir, outputdir, - sleepdiary, configfile, do.Counts) + sleepdiary, configfile) }, args = list(GGIRshiny = GGIRshiny, rawaccdir = isolate(global$raw_acc_in), outputdir = global$data_out, sleepdiary = sleepdiaryfile_local, - configfile = cleanPath(paste0(global$data_out, "/config.csv")), - do.Counts = do.Counts), + configfile = cleanPath(paste0(global$data_out, "/config.csv"))), stdout = "", stderr = "") @@ -867,11 +858,15 @@ myApp <- function(homedir=getwd(), ...) { observe({ if (x_ggir$poll_io(0)[["process"]] != "ready") { # Copy local log file to server to update progress log - if (file.exists(logfile)) file.copy(from = logfile, to = stdout_GGIR_tmp, overwrite = TRUE) + if (file.exists(logfile)) { + file.copy(from = logfile, to = stdout_GGIR_tmp, overwrite = TRUE) + } invalidateLater(2000) } else { # Copy local log file to server to update progress log - if (file.exists(logfile)) file.copy(from = logfile, to = stdout_GGIR_tmp, overwrite = TRUE) + if (file.exists(logfile)) { + file.copy(from = logfile, to = stdout_GGIR_tmp, overwrite = TRUE) + } on.exit(removeNotification(id_ggir), add = TRUE) # Delete Rscript that is created by GGIRshiny because user does not need this @@ -884,14 +879,14 @@ myApp <- function(homedir=getwd(), ...) { expected_outputdir_ggir = paste0(global$data_out, "/output_", basename(global$raw_acc_in)) expected_ggiroutput_file = paste0(global$data_out, "/output_", basename(global$raw_acc_in), "/results/part2_daysummary.csv") if (file.exists(expected_ggiroutput_file) == TRUE) { # checks whether ggir output was created - GGIRCounts_message = paste0(#"GGIR successfully completed at ", Sys.time(), + GGIR_message = paste0(#"GGIR successfully completed at ", Sys.time(), "Output is stored in: ", #
expected_outputdir_ggir, "
The table below shows the content of part2_daysummary.csv:") GGIRpart2 = read.csv(expected_ggiroutput_file, nrow = 100) output$GGIRpart2 <- DT::renderDataTable(GGIRpart2, options = list(scrollX = TRUE)) output$ggir_end_message <- renderUI({ - HTML(paste0(GGIRCounts_message)) + HTML(paste0(GGIR_message)) }) } } @@ -976,6 +971,7 @@ myApp <- function(homedir=getwd(), ...) { configfile = paste0(global$data_out, "/config_hbGPS.csv")), stdout = stdout_hbGPS_tmp, stderr = "2>&1") + observe({ if (x_hbGPS$poll_io(0)[["process"]] != "ready") { invalidateLater(5000) diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..d6a6357 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,14 @@ +comment: false + +coverage: + status: + project: + default: + target: auto + threshold: 1% + informational: true + patch: + default: + target: auto + threshold: 1% + informational: true \ No newline at end of file diff --git a/inst/testfiles_ggir/example_config_files_GGIR.zip b/inst/testfiles_ggir/example_config_files_GGIR.zip index 739b17c..afc611b 100644 Binary files a/inst/testfiles_ggir/example_config_files_GGIR.zip and b/inst/testfiles_ggir/example_config_files_GGIR.zip differ diff --git a/man/GGIRshiny.Rd b/man/GGIRshiny.Rd index e087542..518d9ab 100644 --- a/man/GGIRshiny.Rd +++ b/man/GGIRshiny.Rd @@ -4,13 +4,7 @@ \alias{GGIRshiny} \title{GGIRshiny} \usage{ -GGIRshiny( - rawaccdir, - outputdir, - sleepdiary = c(), - configfile = c(), - do.Counts = FALSE -) +GGIRshiny(rawaccdir, outputdir, sleepdiary = c(), configfile = c()) } \arguments{ \item{rawaccdir}{Path to input directory} @@ -20,8 +14,6 @@ GGIRshiny( \item{sleepdiary}{Path to sleep diary} \item{configfile}{Configfile path} - -\item{do.Counts}{Boolean to indicate whether BrondCounts should be derived} } \value{ no object is returned, only a new file is created in the output directory