From 247046327c7d859e61d32c798cb6f82761d7b1ad Mon Sep 17 00:00:00 2001
From: Sebastian Henz <sebastian.henz@ufz.de>
Date: Mon, 16 Mar 2020 15:06:27 +0100
Subject: [PATCH] Set default "which" value to NA. Use empty vectors or NULL to
 show just the axes.

---
 DESCRIPTION        |  4 ++--
 NEWS.md            |  5 +++++
 R/plot_ecxsys.R    |  5 +++--
 R/plot_effect.R    | 12 ++++++------
 R/plot_stress.R    | 12 ++++++------
 man/plot_ecxsys.Rd |  9 +++++----
 6 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index b396809..ee2ef22 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,8 +1,8 @@
 Package: stressaddition
 Type: Package
 Title: Modeling Tri-Phasic Concentration-Response Relationships
-Version: 2.4.0
-Date: 2020-03-13
+Version: 2.4.1
+Date: 2020-03-16
 Authors@R: c(person("Sebastian", 
                     "Henz", 
                     role = c("aut", "cre"), 
diff --git a/NEWS.md b/NEWS.md
index f43297f..bf1b000 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,3 +1,8 @@
+# stressaddition 2.4.1
+
+* Fixed unintended behaviour in `plot_effect()` and `plot_stress()` where supplying an empty vector caused the four standard curves to show. Now setting `which` to an empty vector or `NULL` shows just the axes. The default value is NA.
+* Renamed the `mixture_effect` column in the `predict_mixture` output data frame to `effect`.
+
 # stressaddition 2.4.0
 
 * Improved `plot_effect()` and `plot_stress()`. You can now control whether the observed values (the points) should be plotted using the `which` argument.
diff --git a/R/plot_ecxsys.R b/R/plot_ecxsys.R
index f1cd7ca..e3d1f3e 100644
--- a/R/plot_ecxsys.R
+++ b/R/plot_ecxsys.R
@@ -31,8 +31,9 @@
 #'   \code{model$curves} data frame. There is also \code{"effect_tox_observed"}
 #'   and \code{"effect_tox_env_observed"} for the observed effects and
 #'   \code{"sys_tox_observed"} and \code{"sys_tox_env_observed"} for the
-#'   observed Sys. The default \code{NULL} only plots the most important curves.
-#'   Use \code{which = "all"} to display all curves.
+#'   observed Sys. The default \code{NA} only plots the most important curves.
+#'   Use \code{which = "all"} to display all curves. An empty vector or
+#'   \code{NULL} creates just the axes.
 #'
 #' @param show_legend Should the plot include a legend? Defaults to \code{FALSE}
 #'   because it may cover some parts of the plot depending on the plot size and
diff --git a/R/plot_effect.R b/R/plot_effect.R
index 0645f03..942b3cc 100644
--- a/R/plot_effect.R
+++ b/R/plot_effect.R
@@ -20,7 +20,7 @@
 #' @rdname plot_ecxsys
 #' @export
 plot_effect <- function(model,
-                        which = NULL,
+                        which = NA,
                         show_legend = FALSE,
                         xlab = "concentration",
                         ylab = "effect",
@@ -32,7 +32,7 @@ plot_effect <- function(model,
         curve_names[startsWith(curve_names, "effect")],
         "effect_tox_observed", "effect_tox_env_observed"  # the observed points
     )
-    if (is.null(which)) {
+    if (length(which) == 1 && is.na(which)) {
         which <- c("effect_tox", "effect_tox_sys", "effect_tox_observed")
         if (model$with_env) {
             which <- c(which, "effect_tox_env", "effect_tox_env_sys",
@@ -43,12 +43,12 @@ plot_effect <- function(model,
             stop("'all' must not be combined with other curve names.")
         }
         which <- valid_names
+    } else if (!model$with_env && any(grepl("env", which, fixed = TRUE))) {
+        warning("'which' contains names with 'env' but the model was built ",
+                "without environmental effects.")
+        which <- which[which %in% valid_names]
     } else if (any(!which %in% valid_names)) {
         warning("Argument 'which' contains invalid names.")
-        if (!model$with_env && any(grepl("env", which, fixed = TRUE))) {
-            warning("'which' contains names with 'env' but the model was",
-                    " built without environmental effects.")
-        }
         which <- which[which %in% valid_names]
     }
 
diff --git a/R/plot_stress.R b/R/plot_stress.R
index 296f90a..152b0a3 100644
--- a/R/plot_stress.R
+++ b/R/plot_stress.R
@@ -20,7 +20,7 @@
 #' @rdname plot_ecxsys
 #' @export
 plot_stress <- function(model,
-                        which = NULL,
+                        which = NA,
                         show_legend = FALSE,
                         xlab = "concentration",
                         ylab = "stress",
@@ -32,7 +32,7 @@ plot_stress <- function(model,
         curve_names[startsWith(curve_names, "stress") | startsWith(curve_names, "sys")],
         "sys_tox_observed", "sys_tox_env_observed"  # the observed points
     )
-    if (is.null(which)) {
+    if (length(which) == 1 && is.na(which)) {
         which <- c("sys_tox", "sys_tox_observed")
         if (model$with_env) {
             which <- c(which, "sys_tox_env", "sys_tox_env_observed")
@@ -42,12 +42,12 @@ plot_stress <- function(model,
             stop("'all' must not be combined with other curve names.")
         }
         which <- valid_names
+    } else if (!model$with_env && any(grepl("env", which, fixed = TRUE))) {
+        warning("'which' contains names with 'env' but the model was built ",
+                "without environmental effects.")
+        which <- which[which %in% valid_names]
     } else if (any(!which %in% valid_names)) {
         warning("Argument 'which' contains invalid names.")
-        if (!model$with_env && any(grepl("env", which, fixed = TRUE))) {
-            warning("'which' contains names with 'env' but the model was",
-                    " built without environmental effects.")
-        }
         which <- which[which %in% valid_names]
     }
 
diff --git a/man/plot_ecxsys.Rd b/man/plot_ecxsys.Rd
index 1c9c32f..1b5e970 100644
--- a/man/plot_ecxsys.Rd
+++ b/man/plot_ecxsys.Rd
@@ -8,7 +8,7 @@
 \usage{
 plot_effect(
   model,
-  which = NULL,
+  which = NA,
   show_legend = FALSE,
   xlab = "concentration",
   ylab = "effect",
@@ -17,7 +17,7 @@ plot_effect(
 
 plot_stress(
   model,
-  which = NULL,
+  which = NA,
   show_legend = FALSE,
   xlab = "concentration",
   ylab = "stress",
@@ -31,8 +31,9 @@ plot_stress(
 \code{model$curves} data frame. There is also \code{"effect_tox_observed"}
 and \code{"effect_tox_env_observed"} for the observed effects and
 \code{"sys_tox_observed"} and \code{"sys_tox_env_observed"} for the
-observed Sys. The default \code{NULL} only plots the most important curves.
-Use \code{which = "all"} to display all curves.}
+observed Sys. The default \code{NA} only plots the most important curves.
+Use \code{which = "all"} to display all curves. An empty vector or
+\code{NULL} creates just the axes.}
 
 \item{show_legend}{Should the plot include a legend? Defaults to \code{FALSE}
 because it may cover some parts of the plot depending on the plot size and
-- 
GitLab