Commit 8bd016c3 authored by Chris Holbrook's avatar Chris Holbrook

fix output csv file name bug when multiple vrl input; make single call to vue...

fix output csv file name bug when multiple vrl input; make single call to vue convert for each file; add progress bar; improve error messaging.
parent b38508b7
......@@ -2,8 +2,8 @@ Package: glatos
Type: Package
Title: A package for the Great Lakes Acoustic Telemetry Observation System
Description: Functions useful to members of the Great Lakes Acoustic Telemetry Observation System www.glatos.glos.us; many more broadly relevant to simulating, processing, analysing, and visualizing acoustic telemetry data.
Version: 0.3.2.9002
Date: 2019-03-25
Version: 0.3.2.9003
Date: 2019-06-07
Depends: R (>= 3.2.0)
Imports:
cellranger,
......
# glatos 0.3.2
#### 2019-03-25
#### 2019-06-07
### bug fixes and minor changes
-vrl2csv
- fixed bug where output csv file names were not returned when input
was multiple VRL file names. A vector of output CSV file names
is now returned.
- make separate call to VUE --convert-files for each VRL file.
- add progress bar
- improve error messaging.
- detect_transmissions
- fixed bug where 'trns_x' and 'trns_y' in data slot of output was not
converted to input coordinate reference system when *sp_out = TRUE*.
......
......@@ -78,16 +78,17 @@ vrl2csv <- function(vrl, outDir=NA, overwrite=TRUE, vueExePath=NA){
#if vrl is single directory, get list of vrl file names
if(all(file.info(vrl)$isdir)) {
if(!file.exists(vrl)) stop(paste0("File or folder ",vrl," not found."))
if(length(vrl) > 1)
stop("input argument 'vrl' cannot include more than one directory")
if(length(vrl) == 0) stop(paste0("No VRL files found at ",vrl))
if(length(vrl) == 1) vrl <- list.files(vrl,full.names=T,
pattern=".vrl$|.VRL$|.Vrl$")
if(length(vrl) > 1) stop("input argument 'vrl' cannot include more than ",
"one directory")
if(length(vrl) == 1) vrl <- list.files(vrl, full.names = TRUE,
pattern = "vrl$", ignore.case = TRUE)
if(length(vrl) == 0) stop("No VRL files found.")
} #end if
#combine multiple vrl files into one string
if(length(vrl) > 0) vrl <- paste(vrl,collapse=" ")
#check if missing
missing_vrls <- which(!file.exists(vrl))
if(length(missing_vrls) > 0) stop("VRL files not found: \n ",
paste(basename(vrl)[missing_vrls], collapse = "\n "))
#set output directory to working directory if not specified
if(is.na(outDir)) outDir <- getwd()
......@@ -95,15 +96,24 @@ vrl2csv <- function(vrl, outDir=NA, overwrite=TRUE, vueExePath=NA){
#set --overwrite-files option
overwrite_file <- ifelse(overwrite,"--overwrite-file","")
#invoke vue command
foo <- system2(vuePath,c("--convert-files",
paste0("--output-path ",outDir),overwrite_file,paste0(" --output-format csv ",vrl)))
if(foo == '127') stop(paste0("\nVUE.exe was not found.\n",
"Ensure that VUE is installed on your system and that either the \n",
"PATH environment variable was set (see ?vrl2csv).\n",
"or specify the path to VUE.exe using the 'vueExePath' argument.\n"))
#invoke vue command for each file
for(i in 1:length(vrl)){
if(i == 1) {
message("Converting ", length(vrl), " detection files...")
pb <- txtProgressBar(0, max = length(vrl), style = 3)
}
foo_i <- system2(vuePath,c("--convert-files",
paste0("--output-path ", outDir), overwrite_file,
paste0(" --output-format csv ", vrl[i])))
if(foo_i == '127') stop("VUE.exe was not found.\n",
" Ensure that VUE is installed on your system and that either the \n",
" PATH environment variable was set (see ?vrl2csv).\n",
" or specify the path to VUE.exe using the 'vueExePath' argument.\n")
setTxtProgressBar(pb, i)
} #end i
#return output path(s) and file name(s)
outFName <- gsub(".vrl|.VRL|.Vrl",".csv",basename(vrl))
return(paste0(outDir,"/",outFName))
outFName <- gsub("vrl$", "csv", basename(vrl), ignore.case = TRUE)
return(file.path(outDir, outFName))
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment