From 4e59dc0b5eeb6cac3ffc9c26e85cccd9a5c61a59 Mon Sep 17 00:00:00 2001 From: dankelley Date: Wed, 18 Dec 2019 13:20:56 -0400 Subject: [PATCH] improve two error messages: 1. for read.oce() on an empty file 2. for plot,echosounder-method() on an unrecognized 'which' value --- R/echosounder.R | 17 +++++++++-------- R/oce.R | 4 +++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/R/echosounder.R b/R/echosounder.R index 7718fbb54c..d018b65a6c 100644 --- a/R/echosounder.R +++ b/R/echosounder.R @@ -578,16 +578,10 @@ setMethod(f="plot", else lay <- layout(matrix(1:2, nrow=2, byrow=TRUE)) } - oceDebug(debug, "which:", which, "\n") + oceDebug(debug, "which before converting to numbers: c(", paste(which, collapse=","), ")\n") whichOrig <- which which <- oce.pmatch(which, list("zt image"=1, "zx image"=2, map=3)) - if (!(which %in% 1:3)) { - if (is.character(whichOrig)) - stop("In plot,echosounder-method : unknown value of which (\"", whichOrig, "\"); try 1, 2 or 3, or, equivalently, \"zt image\", \"zx image\" or \"map\"", call.=FALSE) - else - stop("In plot,echosounder-method : unknown value of which (", whichOrig, "); try 1, 2 or 3, or, equivalently, \"zt image\", \"zx image\" or \"map\"", call.=FALSE) - } - oceDebug(debug, "which:", which, "\n") + oceDebug(debug, "which after converting to numbers: c(", paste(which, collapse=","), ")\n") for (w in seq_along(which)) { oceDebug(debug, "this which:", which[w], "\n") if (which[w] == 1) { @@ -757,6 +751,13 @@ setMethod(f="plot", } } lines(lon, lat, col=if (!is.function(col)) col else "black", lwd=lwd) + } else { + stop("In plot,echosounder-method : unknown value of which (", + if (is.character(whichOrig[w])) { + paste("\"", whichOrig[w], "\"", sep="") + } else { + whichOrig[w] + }, "); try 1, 2 or 3, or, equivalently, \"zt image\", \"zx image\" or \"map\"", call.=FALSE) } } oceDebug(debug, "} # plot.echosounder()\n", unindent=1, style="bold") diff --git a/R/oce.R b/R/oce.R index 0909a6d472..0f16004970 100644 --- a/R/oce.R +++ b/R/oce.R @@ -2024,8 +2024,10 @@ read.oce <- function(file, ...) { if (missing(file)) stop("must supply 'file'") + if (is.character(file) && "http://" != substr(file, 1, 7) && !file.exists(file)) + stop("In read.oce() : cannot open '", file, "' because there is no such file or directory", call.=FALSE) if (is.character(file) && "http://" != substr(file, 1, 7) && 0 == file.info(file)$size) - stop("empty file (read.oce)") + stop("empty file") dots <- list(...) debug <- if ("debug" %in% names(dots)) dots$debug else 0 type <- oceMagic(file, debug=debug-1)