checkExpression <- function(sexpr) { if (is.name(sexpr)) { fcall <- paste(sexpr, "(x)") return(parse(text = fcall)) } else { if (!((is.call(sexpr) || is.expression(sexpr)) && "x" %in% all.vars(sexpr))) stop("'expr' must be a function, or a call or an expression containing 'x'") return(sexpr) } # end if-else } # end function