R/super-file-helpers.R

Defines functions rename_action_to_test_logs clear_test_logs

Documented in clear_test_logs rename_action_to_test_logs

#' Clears out all test logs from given folder
#'
#' @param folder folder which to clean test logs from
#'
#' @export
#'
#' @examples
clear_test_logs <- function(folder){
  # find all test logs
  pth_test <- list.files(folder, pattern = "_test_",
             full.names = TRUE)
  # check if empty
  for(pth in pth_test){
    log <- load_brainvr_log(pth)
    if(nrow(log$data) <= 0) unlink(pth)
  }
  # remove
}

#' Convets action logs to test logs. The outcome is the version 5
#' of the supermarket data due these files originating in the pre version 5 era
#'
#' @param folder folder to edit
#'
#' @export
#'
#' @examples
rename_action_to_test_logs <- function(folder){
  # find all actions logs
  pth_actions <- list.files(folder, pattern = "_actions_",
             full.names = TRUE)
  if(length(pth_actions) <= 0) return()
  for(pth in pth_actions){
    newName <- gsub("supermarket_actions", "test_supermarket-actions", pth)
    file.rename(pth, newName)
  }
}
BrainVR/brainvr-supermarket documentation built on Sept. 16, 2021, 1:27 a.m.