diff --git a/NEWS.md b/NEWS.md index ec6d2bbc8..1833360b1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,8 @@ - Part 1: Fix bug where on machines with GMT timezone and R >= 4.3.0, for GENEActiv .bin files, the starting timestamps of M$metalong and M$metashort were truncated to midninght #1000 +- Part 5: Fix bug where part5 output showed duplicate rows when argument dayborder is set to nondefault value #1006 + # CHANGES IN GGIR VERSION 3.0-2 - Part 2: Fix bug that caused part 2 to struggle with corrupt ActiGraph .gt3x files #972 diff --git a/R/g.analyse.R b/R/g.analyse.R index 24ba307d1..05cec5be6 100644 --- a/R/g.analyse.R +++ b/R/g.analyse.R @@ -67,7 +67,7 @@ g.analyse = function(I, C, M, IMP, params_247 = c(), params_phyact = c(), n_ws2_perday = (1440*60) / ws2 n_ws3_perday = (1440*60) / ws3 if (((nrow(metalong)/((1440*60)/ws2)*10) - (nrow(metashort)/((60/ws3)*1440)) * 10) > 1) { - cat("Matrices 'metalong' and 'metashort' are not compatible") + stop("Matrices 'metalong' and 'metashort' are not compatible") } #---------------------- # Extract ID centrally @@ -168,9 +168,6 @@ g.analyse = function(I, C, M, IMP, params_247 = c(), params_phyact = c(), # LW = length(which(as.numeric(qcheck) != 1)) / (60/ws3) #number of minutes wear time between first and last midnights nfulldays = (lastmidnighti - firstmidnighti) / ((3600/ws2)*24) ndays = length(midnights) + 1 #ceiling(nfulldays + 2) # ceiling to cope with days with 23 hours - if (ndays != round(ndays)) { #day saving time causing trouble? - cat("One day in this measurement is longer or shorter than 24 hours (probably related to day saving time)") - } #------------------------------------- # Detect orientation (at the moment only desighned for hip with accelerometer): # assess which angle per axis is most strongly 24 hour correlated: @@ -279,8 +276,6 @@ g.analyse = function(I, C, M, IMP, params_247 = c(), params_phyact = c(), average24h = average24h / average24hc AveAccAve24hr[h] = mean(average24h) #average acceleration in an average 24 hour cycle } - } else { - cat("file skipped for general average caculation because not enough data") } rm(metalong); rm(metashort) dataqual_summary = data.frame(clipping_score = LC2 / ((LD/1440)*96), diff --git a/R/g.analyse.perday.R b/R/g.analyse.perday.R index bf5ad50bd..a9389c636 100644 --- a/R/g.analyse.perday.R +++ b/R/g.analyse.perday.R @@ -30,12 +30,10 @@ g.analyse.perday = function(ndays, firstmidnighti, time, nfeatures, if (firstmidnighti == 1) { #if measurement starts at midnight ndays = ndays - 1 startatmidnight = 1 - cat("measurement starts at midnight or there is no midnight") } if (lastmidnight == time[length(time)] & nrow(metashort) < ((60/ws3) * 1440)) { #if measurement ends at midnight ndays = ndays - 1 endatmidnight = 1 - cat("measurement ends at midnight or there is no midnight") } } @@ -141,7 +139,7 @@ g.analyse.perday = function(ndays, firstmidnighti, time, nfeatures, if (length(params_247[["qwindow"]]) < 2) params_247[["qwindow"]] = c() if (length(params_247[["qwindow"]]) > 0) { if (length(qwindow_names) == 1) { - cat("Argument to qwindow is invalid, requires a vector of at least length 2") + warning("Argument to qwindow is invalid, requires a vector of at least length 2") } if (length(qwindow_names) == 2) { if (params_247[["qwindow"]][1] != 0 | params_247[["qwindow"]][2] != 24) { diff --git a/R/g.part5.definedays.R b/R/g.part5.definedays.R index b1fcce462..39ca9befb 100644 --- a/R/g.part5.definedays.R +++ b/R/g.part5.definedays.R @@ -34,7 +34,7 @@ g.part5.definedays = function(nightsi, wi, indjump, nightsi_bu, if (nightsi[1] == 1) { wi = wi + 1 # add extra nightsi to get the last day processed (as wi has been increased by 1) - nightsi = c(nightsi, nightsi + (24*(60/epochSize) * 60) - 1) + nightsi = c(nightsi, nightsi[length(nightsi)] + (24*(60/epochSize) * 60)) } if (length(nightsi) >= wi) { if (wi == 1) { @@ -89,13 +89,18 @@ g.part5.definedays = function(nightsi, wi, indjump, nightsi_bu, # in MM, also define segments of the day based on qwindow if (!is.na(qqq[1]) & !is.na(qqq[2])) { fullQqq = qqq[1]:qqq[2] + firstepoch = format(ts$time[qqq[1]], "%H:%M:%S") lastepoch = format(ts$time[qqq[2]], "%H:%M:%S") qnames = NULL if (is.data.frame(qwindow)) { date_of_interest = substr(ts$time[qqq[1]], 1, 10) qdate = which(qwindow$ID == ID & qwindow$date == date_of_interest) - qnames = unlist(qwindow$qwindow_names[qdate]) - qwindow = unlist(qwindow$qwindow_values[qdate]) + if (length(qdate) == 1) { # if ID/date matched with activity log + qnames = unlist(qwindow$qwindow_names[qdate]) + qwindow = unlist(qwindow$qwindow_values[qdate]) + } else { # if ID/date not correctly matched with activity log + qwindow = c(0, 24) + } } breaks = qwindow2timestamp(qwindow, lastepoch = lastepoch) breaks_i = c() @@ -108,7 +113,7 @@ g.part5.definedays = function(nightsi, wi, indjump, nightsi_bu, } # build up segments segments = list(qqq) - segments_timing = paste("00:00:00", lastepoch, sep = "-") + segments_timing = paste(firstepoch, lastepoch, sep = "-") segments_names = "MM" si = 2 do.segments = TRUE diff --git a/R/g.report.part5.R b/R/g.report.part5.R index 810e0e6b0..53f1aac18 100644 --- a/R/g.report.part5.R +++ b/R/g.report.part5.R @@ -119,8 +119,6 @@ g.report.part5 = function(metadatadir = c(), f0 = c(), f1 = c(), loglocation = c out = base::merge(tmp, out, all = TRUE) } if (length(tail_expansion_log) != 0) { - # col2na = grep(pattern = "spt|sleeplog_used", - # x = names(out), value = FALSE) col2na = grep(pattern = paste0("sleep_efficiency|N_atleast5minwakenight|daysleeper|", "daysleeper|sleeplog_used|_spt_sleep|_spt_wake"), x = names(out), value = FALSE) @@ -146,10 +144,8 @@ g.report.part5 = function(metadatadir = c(), f0 = c(), f1 = c(), loglocation = c # order data.frame outputfinal$window_number = as.numeric(gsub(" ", "", outputfinal$window_number)) - # outputfinal_segments = outputfinal[which(!outputfinal$window %in% c("MM", "WW")),] - # outputfinal = outputfinal[which(outputfinal$window %in% c("MM", "WW")),] - outputfinal = outputfinal[order(outputfinal$filename, outputfinal$window, outputfinal$window_number),] - + outputfinal = outputfinal[order(outputfinal$filename, outputfinal$window_number, outputfinal$window), ] + # split results to different spreadsheets in order to minimize individual # filesize and to ease organising dataset uwi = as.character(unique(outputfinal$window)) @@ -475,7 +471,7 @@ g.report.part5 = function(metadatadir = c(), f0 = c(), f1 = c(), loglocation = c } OF3tmp = OF3[, columns2keep] foo34 = function(df,aggPerIndividual,nameold,namenew,cval,window) { - # function to help with calculating additinal variables + # function to help with calculating additional variables # related to counting how many days of measurement there are # that meet a certain criteria # cval is a vector with 0 and 1, indicating whether the criteria is met