Skip to content

Commit

Permalink
allow user to remove unzipped monthly folders by request
Browse files Browse the repository at this point in the history
  • Loading branch information
chrlaney committed Jan 10, 2018
1 parent 77ee7c9 commit 99f17fc
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 8 deletions.
25 changes: 25 additions & 0 deletions neonDataStackR/R/cleanUp.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
##############################################################################################
#' @title Clean up folder after stacking

#' @author
#' Christine Laney \email{claney@battelleecology.org}

#' @description
#' Remove unzipped monthly data folders
#'
#' @keywords internal
#' @param folder The file path to the folder that needs to be cleaned up (the root directory of the data package)
#' @return Any existing directory except for stackedFiles will be removed. Nothing is returned.

#' @references
#' License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007

# Changelog and author contributions / copyrights
# Christine Laney (2018-01-10)
##############################################################################################
cleanUp <- function(folder) {
dirs <- list.dirs(folder, recursive = FALSE)
dirsNotStacked <- dirs[-grep(pattern = "stackedFiles", x = dirs)]
if(length(dirsNotStacked) > 0) {unlink(dirsNotStacked, recursive = TRUE)}
writeLines("All unzipped monthly data folders have been removed.")
}
2 changes: 1 addition & 1 deletion neonDataStackR/R/getProductInfo.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#' @importFrom jsonlite fromJSON
#' @importFrom httr GET
#' @param dpid The data product id (optional), formated as DP0.00000.000
#' @param dpID The data product id (optional), formated as DP0.00000.000
#' @return A data table with product information

#' @references
Expand Down
5 changes: 4 additions & 1 deletion neonDataStackR/R/stackByTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#' @param filepath The location of the zip file
#' @param folder T or F: does the filepath point to a parent, unzipped folder, or a zip file? If F, assumes the filepath points to a zip file. Defaults to F.
#' @param saveUnzippedFiles T or F: should the unzipped monthly data folders be retained?
#' @return All files are unzipped and one file for each table type is created and written.

#' @export
Expand All @@ -23,14 +24,16 @@
# Claire Lunch (2017-09-28)
##############################################################################################

stackByTable <- function(filepath, folder=FALSE){
stackByTable <- function(filepath, folder=FALSE, saveUnzippedFiles = TRUE){
if(folder==FALSE) {
location.data <- substr(filepath, 1, nchar(filepath)-4)
unzipZipfile(zippath = filepath, outpath = location.data, level = "all")
stackDataFiles(location.data)
if(saveUnzippedFiles == FALSE){cleanUp(location.data)}
} else {
unzipZipfile(zippath = filepath, outpath = filepath, level = "in")
stackDataFiles(filepath)
if(saveUnzippedFiles == FALSE){cleanUp(filepath)}
}
}

Expand Down
7 changes: 3 additions & 4 deletions neonDataStackR/R/update_table_types.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
##############################################################################################

update_table_types <- function(){
library(RMySQL)
dps_con <- dbConnect(drv=RMySQL::MySQL(), dbname="dps_database", username="root",password="p@ssw0rd", host="10.206.27.43", root = 3306)
table_types <- dbGetQuery(dps_con, "SELECT * from dpTable WHERE dpTable.tableType NOT IN ('ingest', 'L0prime')")
dps_con <- RMySQL::dbConnect(drv=RMySQL::MySQL(), dbname="dps_database", username="root",password="p@ssw0rd", host="10.206.27.43", root = 3306)
table_types <- RMySQL::dbGetQuery(dps_con, "SELECT * from dpTable WHERE dpTable.tableType NOT IN ('ingest', 'L0prime')")
table_types$tableName <- gsub(pattern = "_pub", replacement = "", x = table_types$tableName)
save(table_types, file = "data/table_types.rda")
dbDisconnect(dps_con)
RMySQL::dbDisconnect(dps_con)
}
24 changes: 24 additions & 0 deletions neonDataStackR/man/cleanUp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion neonDataStackR/man/getProductInfo.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion neonDataStackR/man/stackByTable.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 99f17fc

Please sign in to comment.