aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2015-10-19 15:52:55 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2015-10-19 15:53:37 +0200
commit76084872526d7c6fc6a48e893c8240b323d61a87 (patch)
treed49898118d722e228ed8b7d7ed907bff1a7a6ba0
parent8e709291eb56839b4b5a8f5bf712a53e3ece7d80 (diff)
Make plot.mkinfit work with models where full_name components are NULL
-rw-r--r--R/mkinds.R65
-rw-r--r--R/plot.mkinfit.R2
2 files changed, 67 insertions, 0 deletions
diff --git a/R/mkinds.R b/R/mkinds.R
new file mode 100644
index 00000000..17d40875
--- /dev/null
+++ b/R/mkinds.R
@@ -0,0 +1,65 @@
+# Copyright (C) 2015 Johannes Ranke
+# Contact: jranke@uni-bremen.de
+
+# This file is part of the R package mkin
+
+# mkin is free software: you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>
+
+#' A dataset class for mkin
+#'
+#' @docType class
+#' @importFrom R6 R6Class
+#' @export
+#' @format An \code{\link{R6Class}} generator object.
+#' @field title A full title for the dataset
+#' @field sampling times The sampling times
+#' @field time_unit The time unit
+#' @field observed Names of the observed compounds
+#' @field unit The unit of the observations
+#' @field replicates The number of replicates
+#' @field data A dataframe with at least the columns name, time and value
+#' in order to be compatible with mkinfit
+#' @examples inst/examples/mkinds.R
+mkinds <- R6Class("mkinds",
+ public = list(
+ title = NULL,
+ sampling_times = NULL,
+ time_unit = NULL,
+ observed = NULL,
+ unit = NULL,
+ replicates = NULL,
+ data = NULL,
+
+ initialize = function(title = "", data, time_unit = NA, unit = NA) {
+
+ self$title = title
+ self$sampling_times = unique(data$time)
+ self$time_unit = time_unit
+ self$observed = unique(data$name)
+ self$unit = unit
+ self$replicates = max(by(data, list(data$name, data$time), nrow))
+ self$data = data
+ }
+ )
+)
+
+#' @export
+print.mkinds <- function(x, ...) {
+ cat("<mkinds> with $title: ", x$title, "\n")
+ cat("Observed compounds $observed: ", paste(x$observed, collapse = ", "), "\n")
+ cat("Sampling times $sampling_times: ", paste(x$sampling_times, collapse = ", "), "\n")
+ cat("With a maximum of ", x$replicates, " replicates\n")
+ if (!is.na(x$time_unit)) cat("Time units: ", x$time_units, "\n")
+ if (!is.na(x$unit)) cat("Observation units: ", x$units, "\n")
+}
diff --git a/R/plot.mkinfit.R b/R/plot.mkinfit.R
index f8ee600e..6ca7e531 100644
--- a/R/plot.mkinfit.R
+++ b/R/plot.mkinfit.R
@@ -77,8 +77,10 @@ plot.mkinfit <- function(x, fit = x,
matlines(out$time, out[obs_vars], col = col_obs[obs_vars], lty = lty_obs[obs_vars])
if (legend == TRUE) {
legend_names = lapply(names(fit$mkinmod$spec), function(x) {
+ if (!is.null(fit$mkinmod$spec[[x]]$full_name))
if (is.na(fit$mkinmod$spec[[x]]$full_name)) x
else fit$mkinmod$spec[[x]]$full_name
+ else x
})
legend(lpos, inset= inset, legend = legend_names,
col = col_obs[obs_vars], pch = pch_obs[obs_vars], lty = lty_obs[obs_vars])

Contact - Imprint