From 5b851f3fdfeb86d4ae7bd3859e3b69e14e6cd01f Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Sat, 24 Oct 2015 11:16:28 +0200 Subject: Collect also observed model variables in gmkinws field observed --- R/gmkinws.R | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'R') diff --git a/R/gmkinws.R b/R/gmkinws.R index d40294d..9ef68e1 100644 --- a/R/gmkinws.R +++ b/R/gmkinws.R @@ -74,7 +74,7 @@ gmkinws <- R6Class("gmkinws", add_ds = function(ds) { self$check_ds(ds) - if (is.na(self$ds)) self$ds <- plyr::compact(ds) + if (is.na(self$ds[1])) self$ds <- plyr::compact(ds) else self$ds <- append(self$ds, plyr::compact(ds)) self$update_observed() @@ -83,9 +83,13 @@ gmkinws <- R6Class("gmkinws", }, update_observed = function() { - if (is.na(self$ds[1])) self$observed = NULL - else self$observed = na.omit(unique(unlist(sapply(self$ds, function(x) - x$observed)))) + observed_ds <- if (is.na(self$ds[1])) NULL + else na.omit(unique(unlist(sapply(self$ds, function(x) x$observed)))) + + observed_m <- if (is.na(self$m[1])) NULL + else na.omit(unique(unlist(sapply(self$m, function(x) names(x$spec))))) + + self$observed = union(observed_ds, observed_m) }, delete_ds = function(i) { @@ -110,8 +114,11 @@ gmkinws <- R6Class("gmkinws", add_m = function(m) { self$check_m(m) - if (is.na(self$m)) self$m <- plyr::compact(m) + if (is.na(self$m[1])) self$m <- plyr::compact(m) else self$m = append(self$m, plyr::compact(m)) + + self$update_observed() + invisible(self) }, -- cgit v1.2.1