diff --git a/neonDataStackR/R/cleanUp.R b/neonDataStackR/R/cleanUp.R new file mode 100644 index 0000000..842a352 --- /dev/null +++ b/neonDataStackR/R/cleanUp.R @@ -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.") +} diff --git a/neonDataStackR/R/getProductInfo.R b/neonDataStackR/R/getProductInfo.R index 2f05f96..33925b1 100644 --- a/neonDataStackR/R/getProductInfo.R +++ b/neonDataStackR/R/getProductInfo.R @@ -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 diff --git a/neonDataStackR/R/stackByTable.R b/neonDataStackR/R/stackByTable.R index e8e5b12..d935754 100644 --- a/neonDataStackR/R/stackByTable.R +++ b/neonDataStackR/R/stackByTable.R @@ -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 @@ -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)} } } diff --git a/neonDataStackR/R/update_table_types.R b/neonDataStackR/R/update_table_types.R index 92ea85a..a673d0c 100644 --- a/neonDataStackR/R/update_table_types.R +++ b/neonDataStackR/R/update_table_types.R @@ -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) } diff --git a/neonDataStackR/man/cleanUp.Rd b/neonDataStackR/man/cleanUp.Rd new file mode 100644 index 0000000..44ebbc9 --- /dev/null +++ b/neonDataStackR/man/cleanUp.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/cleanUp.R +\name{cleanUp} +\alias{cleanUp} +\title{Clean up folder after stacking} +\usage{ +cleanUp(folder) +} +\arguments{ +\item{folder}{The file path to the folder that needs to be cleaned up (the root directory of the data package)} +} +\value{ +Any existing directory except for stackedFiles will be removed. Nothing is returned. +} +\description{ +Remove unzipped monthly data folders +} +\references{ +License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 +} +\author{ +Christine Laney \email{claney@battelleecology.org} +} +\keyword{internal} diff --git a/neonDataStackR/man/getProductInfo.Rd b/neonDataStackR/man/getProductInfo.Rd index dcaedbc..0d72769 100644 --- a/neonDataStackR/man/getProductInfo.Rd +++ b/neonDataStackR/man/getProductInfo.Rd @@ -7,7 +7,7 @@ getProductInfo(dpID) } \arguments{ -\item{dpid}{The data product id (optional), formated as DP0.00000.000} +\item{dpID}{The data product id (optional), formated as DP0.00000.000} } \value{ A data table with product information diff --git a/neonDataStackR/man/stackByTable.Rd b/neonDataStackR/man/stackByTable.Rd index c0dffa9..4040938 100644 --- a/neonDataStackR/man/stackByTable.Rd +++ b/neonDataStackR/man/stackByTable.Rd @@ -4,12 +4,14 @@ \alias{stackByTable} \title{Join data files in a zipped NEON data package by table type} \usage{ -stackByTable(filepath, folder = FALSE) +stackByTable(filepath, folder = FALSE, saveUnzippedFiles = TRUE) } \arguments{ \item{filepath}{The location of the zip file} \item{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.} + +\item{saveUnzippedFiles}{T or F: should the unzipped monthly data folders be retained?} } \value{ All files are unzipped and one file for each table type is created and written.