From e27a3633f9513223b68d18946107c535b04b7e76 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Tue, 20 Jun 2017 04:39:42 +0200 Subject: [PATCH] fetch_data: fixed bug with missing evid and mdv --- R/fetch_data.R | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/R/fetch_data.R b/R/fetch_data.R index 154c4c24..0a25af42 100644 --- a/R/fetch_data.R +++ b/R/fetch_data.R @@ -38,12 +38,20 @@ data_opt <- function(problem = NULL, # Create shortcut functions on the fly to filter observations only_obs <- function(xpdb, problem, quiet) { mdv_var <- xp_var(xpdb, problem, type = c('evid', 'mdv'))$col[1] - string <- c('Filtering data by ', mdv_var, ' == 0') fun <- function(x) {} - body(fun) <- bquote({ - msg(.(string), .(quiet)) - x[x[, .(mdv_var)] == 0, ] - }) + if (!is.null(mdv_var)) { + string <- c('Filtering data by ', mdv_var, ' == 0') + body(fun) <- bquote({ + msg(.(string), .(quiet)) + x[x[, .(mdv_var)] == 0, ] + }) + } else { + string <- c('No `evid` or `mdv` variable available to filter the data.') + body(fun) <- bquote({ + msg(.(string), .(quiet)) + x + }) + } fun }