Running examples in ‘model4you-Ex.R’ failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: pmforest
> ### Title: Compute model-based forest from model.
> ### Aliases: pmforest gettree.pmforest
> 
> ### ** Examples
> 
> library("model4you")
> 
> if(require("mvtnorm") & require("survival")) {
+   
+   ## function to simulate the data
+   sim_data <- function(n = 500, p = 10, beta = 3, sd = 1){
+     
+     ## treatment
+     lev <- c("C", "A")
+     a <- rep(factor(lev, labels = lev, levels = lev), length = n)
+     
+     ## correlated z variables
+     sigma <- diag(p) 
+     sigma[sigma == 0] <- 0.2
+     ztemp <- rmvnorm(n, sigma = sigma)
+     z <- (pnorm(ztemp) * 2 * pi) - pi  
+     colnames(z) <- paste0("z", 1:ncol(z))
+     z1 <- z[,1]
+     
+     ## outcome
+     y <- 7 + 0.2 * (a %in% "A") + beta * cos(z1) * (a %in% "A") + rnorm(n, 0, sd)
+     
+     data.frame(y = y, a = a, z)
+   }
+   
+   ## simulate data
+   set.seed(123)
+   beta <- 3
+   ntrain <- 500
+   ntest <- 50
+   simdata <- simdata_s <- sim_data(p = 5, beta = beta, n = ntrain)
+   tsimdata <- tsimdata_s <- sim_data(p = 5, beta = beta, n = ntest)
+   simdata_s$cens <- rep(1, ntrain)
+   tsimdata_s$cens <- rep(1, ntest)
+   
+   ## base model
+   basemodel_lm <- lm(y ~ a, data = simdata)
+   
+   ## forest
+   frst_lm <- pmforest(basemodel_lm, ntree = 20, 
+                       perturb = list(replace = FALSE, fraction = 0.632),
+                       control = ctree_control(mincriterion = 0))
+   
+   ## personalised models
+   # (1) return the model objects
+   pmodels_lm <- pmodel(x = frst_lm, newdata = tsimdata, fun = identity)
+   class(pmodels_lm)
+   # (2) return coefficients only (default)
+   coefs_lm <- pmodel(x = frst_lm, newdata = tsimdata)
+   
+   # compare predictive objective functions of personalised models versus
+   # base model
+   sum(objfun(pmodels_lm)) # -RSS personalised models
+   sum(objfun(basemodel_lm, newdata = tsimdata)) # -RSS base model
+   
+   
+   if(require("ggplot2")) {
+     ## dependence plot
+     dp_lm <- cbind(coefs_lm, tsimdata)
+     ggplot(tsimdata) +
+       stat_function(fun = function(z1) 0.2 + beta * cos(z1), 
+                     aes(color = "true treatment\neffect")) +
+       geom_point(data = dp_lm, 
+                  aes(y = aA, x = z1, color = "estimates lm"), 
+                  alpha = 0.5)  +
+       ylab("treatment effect") + 
+       xlab("patient characteristic z1")
+   }
+ }
Loading required package: survival
No data given. I'm using data set simdata from the current environment parent.frame(). Please check if that is what you want.
Warning in model.frame.default(object$predictf, data = newdata, na.action = na.pass,  :
  variable 'a' is not a factor
Warning in model.frame.default(object$predictf, data = newdata, na.action = na.pass,  :
  variable 'a' is not a factor
 ----------- FAILURE REPORT -------------- 
 --- failure: the condition has length > 1 ---
 --- srcref --- 
: 
 --- package (from environment) --- 
model4you
 --- call from context --- 
pmodel(x = frst_lm, newdata = tsimdata)
 --- call from argument --- 
if (class(ret) == "matrix") ret <- t(ret)
 --- R stacktrace ---
where 1: pmodel(x = frst_lm, newdata = tsimdata)

 --- value of length: 2 type: logical ---
[1]  TRUE FALSE
 --- function from context --- 
function (x = NULL, model = NULL, newdata = NULL, OOB = TRUE, 
    fun = coef, return_attr = c("modelcall", "data", "similarity")) 
{
    if (is.matrix(x)) {
        if (is.null(model)) 
            stop("When x is a matrix, model must not be NULL. Please enter a model object.")
        pweights <- x
    }
    else {
        if (is.null(model)) 
            model <- x$info$model
        pweights <- predict(x, type = "weights", newdata = newdata, 
            OOB = OOB)
    }
    get_pmod <- function(w) {
        if (sum(w) == 0) 
            stop("The weights for one observation are all 0. A solution may be increasing ntree.")
        dat <- x$data
        dat$w <- w
        pmod <- update(model, weights = w, subset = w > 0, data = dat)
        fun(pmod)
    }
    ret <- apply(pweights, 2, get_pmod)
    if (class(ret) == "matrix") 
        ret <- t(ret)
    if (all.equal(fun, identity) == TRUE) 
        class(ret) <- c("pmodel_identity", class(ret))
    class(ret) <- c("pmodel", class(ret))
    if ("modelcall" %in% return_attr) 
        attr(ret, "modelcall") <- getCall(model)
    if ("data" %in% return_attr) 
        if (is.null(newdata)) 
            attr(ret, "data") <- x$data
        else attr(ret, "data") <- newdata
    if ("similarity" %in% return_attr) 
        attr(ret, "similarity") <- pweights
    return(ret)
}
<bytecode: 0x55870ff8b878>
<environment: namespace:model4you>
 --- function search by body ---
Function pmodel in namespace model4you has this body.
 ----------- END OF FAILURE REPORT -------------- 
Fatal error: the condition has length > 1