From c8107ee80bc06e5584342b2ecb439ff12ab4bcb2 Mon Sep 17 00:00:00 2001
From: Ben Anderson <dataknut@icloud.com>
Date: Fri, 27 Apr 2018 12:51:25 +1200
Subject: [PATCH] new

---
 greenGridr/R/listGridSpyFiles.R | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644 greenGridr/R/listGridSpyFiles.R

diff --git a/greenGridr/R/listGridSpyFiles.R b/greenGridr/R/listGridSpyFiles.R
new file mode 100644
index 0000000..e6f2001
--- /dev/null
+++ b/greenGridr/R/listGridSpyFiles.R
@@ -0,0 +1,26 @@
+#' List all available Grid Spy data files
+#'
+#' \code{list1mGridSpyFiles}. Lists all available 1 minute grid spy files from data repository. The functions, like most others in this package will fail
+#'    if you do not have the data in a folder/directory corresponding to 'path'. Code borrows extensively from similar SAVE project function.
+#'    This could take quite a long time if you have a lot of files.
+#' @param fpath the name of the directory where the function should look
+#' @param pattern a pattern to match. Use the pattern to filter e.g. 1m (xx_at1.csv) from 30s () files
+#'
+#' @author Ben Anderson, \email{b.anderson@@soton.ac.uk}
+#' @export
+#'
+list1mGridSpyFiles <- function(fpath, pattern){
+  # /Volumes/hum-csafe/Research Projects/GREEN Grid/_RAW DATA/GridSpyData
+  # "*at1.csv$"
+  print(paste0("Looking for files matching ", pattern, " in ", fpath))
+  fileListDT <- as.data.table(list.files(path = fpath, pattern = pattern, # use the pattern to filter e.g. 1m from 30s files
+                                         recursive = TRUE))
+  fileListDT <- fileListDT[,
+                           c("hhID","fileName") :=  tstrsplit(V1, "/") # get actual household id & filename
+                           ]
+  fileListDT <- fileListDT[,
+                           fullPath := paste0(fpath,"/",V1) # get actual file name
+                           ]
+  print(paste0("Found ", tidyNum(nrow(fileListDT)), " of them."))
+  return(fileListDT)
+}
-- 
GitLab