Errors in running code in vignettes:
when running code in ‘constparty.Rnw’
  ...

> options(width = 70)

> library("partykit")
Loading required package: grid
Loading required package: libcoin
Loading required package: mvtnorm
Loading required package: rpart

> set.seed(290875)

> data("Titanic", package = "datasets")

> ttnc <- as.data.frame(Titanic)

> ttnc <- ttnc[rep(1:nrow(ttnc), ttnc$Freq), 1:4]

> names(ttnc)[2] <- "Gender"

> library("rpart")

> (rp <- rpart(Survived ~ ., data = ttnc, model = TRUE))
n= 2201 

node), split, n, loss, yval, (yprob)
      * denotes terminal node

 1) root 2201 711 No (0.6769650 0.3230350)  
   2) Gender=Male 1731 367 No (0.7879838 0.2120162)  
     4) Age=Adult 1667 338 No (0.7972406 0.2027594) *
     5) Age=Child 64  29 No (0.5468750 0.4531250)  
      10) Class=3rd 48  13 No (0.7291667 0.2708333) *
      11) Class=1st,2nd 16   0 Yes (0.0000000 1.0000000) *
   3) Gender=Female 470 126 Yes (0.2680851 0.7319149)  
     6) Class=3rd 196  90 No (0.5408163 0.4591837) *
     7) Class=1st,2nd,Crew 274  20 Yes (0.0729927 0.9270073) *

> (party_rp <- as.party(rp))

Model formula:
Survived ~ Class + Gender + Age

Fitted party:
[1] root
|   [2] Gender in Male
|   |   [3] Age in Adult: No (n = 1667, err = 20.3%)
|   |   [4] Age in Child
|   |   |   [5] Class in 3rd: No (n = 48, err = 27.1%)
|   |   |   [6] Class in 1st, 2nd: Yes (n = 16, err = 0.0%)
|   [7] Gender in Female
|   |   [8] Class in 3rd: No (n = 196, err = 45.9%)
|   |   [9] Class in 1st, 2nd, Crew: Yes (n = 274, err = 7.3%)

Number of inner nodes:    4
Number of terminal nodes: 5

> plot(rp)

> text(rp)

> plot(party_rp)

> all.equal(predict(rp), predict(party_rp, type = "prob"), 
+     check.attributes = FALSE)
[1] TRUE

> str(fitted(party_rp))
'data.frame':	2201 obs. of  2 variables:
 $ (fitted)  : int  5 5 5 5 5 5 5 5 5 5 ...
 $ (response): Factor w/ 2 levels "No","Yes": 1 1 1 1 1 1 1 1 1 1 ...

> prop.table(do.call("table", fitted(party_rp)), 1)
        (response)
(fitted)        No       Yes
       3 0.7972406 0.2027594
       5 0.7291667 0.2708333
       6 0.0000000 1.0000000
       8 0.5408163 0.4591837
       9 0.0729927 0.9270073

> if (require("RWeka")) {
+     j48 <- J48(Survived ~ ., data = ttnc)
+ } else {
+     j48 <- rpart(Survived ~ ., data = ttnc)
+ }
Loading required package: RWeka

> print(j48)
J48 pruned tree
------------------

Gender = Male
|   Class = 1st
|   |   Age = Child: Yes (5.0)
|   |   Age = Adult: No (175.0/57.0)
|   Class = 2nd
|   |   Age = Child: Yes (11.0)
|   |   Age = Adult: No (168.0/14.0)
|   Class = 3rd: No (510.0/88.0)
|   Class = Crew: No (862.0/192.0)
Gender = Female
|   Class = 1st: Yes (145.0/4.0)
|   Class = 2nd: Yes (106.0/13.0)
|   Class = 3rd: No (196.0/90.0)
|   Class = Crew: Yes (23.0/3.0)

Number of Leaves  : 	10

Size of the tree : 	15


> (party_j48 <- as.party(j48))

Model formula:
Survived ~ Class + Gender + Age

Fitted party:
[1] root
|   [2] Gender in Male
|   |   [3] Class in 1st
|   |   |   [4] Age in Child: Yes (n = 5, err = 0.0%)
|   |   |   [5] Age in Adult: No (n = 175, err = 32.6%)
|   |   [6] Class in 2nd
|   |   |   [7] Age in Child: Yes (n = 11, err = 0.0%)
|   |   |   [8] Age in Adult: No (n = 168, err = 8.3%)
|   |   [9] Class in 3rd: No (n = 510, err = 17.3%)
|   |   [10] Class in Crew: No (n = 862, err = 22.3%)
|   [11] Gender in Female
|   |   [12] Class in 1st: Yes (n = 145, err = 2.8%)
|   |   [13] Class in 2nd: Yes (n = 106, err = 12.3%)
|   |   [14] Class in 3rd: No (n = 196, err = 45.9%)
|   |   [15] Class in Crew: Yes (n = 23, err = 13.0%)

Number of inner nodes:     5
Number of terminal nodes: 10

> plot(party_j48)

> all.equal(predict(j48, type = "prob"), predict(party_j48, 
+     type = "prob"), check.attributes = FALSE)
[1] TRUE

> ttnc_pmml <- file.path(system.file("pmml", package = "partykit"), 
+     "ttnc.pmml")

> (ttnc_quest <- pmmlTreeModel(ttnc_pmml))
Loading required namespace: XML

Model formula:
Survived ~ Gender + Class + Age

Fitted party:
[1] root
|   [2] Gender in Female
|   |   [3] Class in 3rd, Crew: Yes (n = 219, err = 49.8%)
|   |   [4] Class in 1st, 2nd
|   |   |   [5] Class in 2nd: Yes (n = 106, err = 12.3%)
|   |   |   [6] Class in 1st: Yes (n = 145, err = 2.8%)
|   [7] Gender in Male
|   |   [8] Class in 3rd, 2nd, Crew
|   |   |   [9] Age in Child: No (n = 59, err = 40.7%)
|   |   |   [10] Age in Adult
|   |   |   |   [11] Class in 3rd, Crew
|   |   |   |   |   [12] Class in Crew: No (n = 862, err = 22.3%)
|   |   |   |   |   [13] Class in 3rd: No (n = 462, err = 16.2%)
|   |   |   |   [14] Class in 2nd: No (n = 168, err = 8.3%)
|   |   [15] Class in 1st: No (n = 180, err = 34.4%)

Number of inner nodes:    7
Number of terminal nodes: 8

> plot(ttnc_quest)

> ttnc2 <- ttnc[, names(ttnc_quest$data)]

> for (n in names(ttnc2)) {
+     if (is.factor(ttnc2[[n]])) 
+         ttnc2[[n]] <- factor(ttnc2[[n]], levels = levels(ttnc_quest$data[[n]]))
+ }

> ttnc_quest2 <- party(ttnc_quest$node, data = ttnc2, 
+     fitted = data.frame(`(fitted)` = predict(ttnc_quest, ttnc2, 
+         type = "node"), `( .... [TRUNCATED] 

> ttnc_quest2 <- as.constparty(ttnc_quest2)

> plot(ttnc_quest2)

> library("pmml")
Loading required package: XML

> tfile <- tempfile()

> write(toString(pmml(rp)), file = tfile)

> (party_pmml <- pmmlTreeModel(tfile))

Model formula:
Survived ~ Class + Gender + Age

Fitted party:
[1] root
|   [2] Gender in Male
|   |   [3] Age in Adult: No (n = 1667, err = 20.3%)
|   |   [4] Age in Child
|   |   |   [5] Class in 3rd: No (n = 48, err = 27.1%)
|   |   |   [6] Class in 1st, 2nd: Yes (n = 16, err = 0.0%)
|   [7] Gender in Female
|   |   [8] Class in 3rd: No (n = 196, err = 45.9%)
|   |   [9] Class in 1st, 2nd, Crew: Yes (n = 274, err = 7.3%)

Number of inner nodes:    4
Number of terminal nodes: 5

> all.equal(predict(party_rp, newdata = ttnc, type = "prob"), 
+     predict(party_pmml, newdata = ttnc, type = "prob"), check.attributes = FALSE)
[1] TRUE

> findsplit <- function(response, data, weights, alpha = 0.01) {
+     y <- factor(rep(data[[response]], weights))
+     mychisqtest <- function(x) {
 .... [TRUNCATED] 

> growtree <- function(id = 1, response, data, weights, 
+     minbucket = 30) {
+     if (sum(weights) < minbucket) 
+         return(partynode(id =  .... [TRUNCATED] 

> mytree <- function(formula, data, weights = NULL) {
+     response <- all.vars(formula)[1]
+     data <- data[complete.cases(data), c(all.vars(formu .... [TRUNCATED] 

> (myttnc <- mytree(Survived ~ Class + Age + Gender, 
+     data = ttnc))

Model formula:
Survived ~ Class + Age + Gender

Fitted party:
[1] root
|   [2] Gender in Male
|   |   [3] Class in 1st
|   |   |   [4] Age in Child: Yes (n = 5, err = 0.0%)
|   |   |   [5] Age in Adult: No (n = 175, err = 32.6%)
|   |   [6] Class in 2nd, 3rd, Crew
|   |   |   [7] Age in Child
|   |   |   |   [8] Class in 2nd: Yes (n = 11, err = 0.0%)
|   |   |   |   [9] Class in 3rd: No (n = 48, err = 27.1%)
|   |   |   [10] Age in Adult
|   |   |   |   [11] Class in Crew: No (n = 862, err = 22.3%)
|   |   |   |   [12] Class in 2nd, 3rd: No (n = 630, err = 14.1%)
|   [13] Gender in Female
|   |   [14] Class in 3rd: No (n = 196, err = 45.9%)
|   |   [15] Class in 1st, 2nd, Crew: Yes (n = 274, err = 7.3%)

Number of inner nodes:    7
Number of terminal nodes: 8

> plot(myttnc)

> nid <- nodeids(myttnc)

> iid <- nid[!(nid %in% nodeids(myttnc, terminal = TRUE))]

> (pval <- unlist(nodeapply(myttnc, ids = iid, FUN = function(n) info_node(n)$p.value)))
           1            2            3            6            7 
0.000000e+00 2.965383e-06 1.756527e-03 6.933623e-05 8.975754e-06 
          10           13 
2.992870e-05 0.000000e+00 

> myttnc2 <- nodeprune(myttnc, ids = iid[pval > 1e-05])

  When sourcing ‘constparty.R’:
Error: no applicable method for ‘nodeids’ applied to an object of class "NULL"
Execution halted
when running code in ‘partykit.Rnw’
  ...

> options(width = 70)

> library("partykit")
Loading required package: grid
Loading required package: libcoin
Loading required package: mvtnorm
Loading required package: rpart

> set.seed(290875)

> data("WeatherPlay", package = "partykit")

> WeatherPlay
    outlook temperature humidity windy play
1     sunny          85       85 false   no
2     sunny          80       90  true   no
3  overcast          83       86 false  yes
4     rainy          70       96 false  yes
5     rainy          68       80 false  yes
6     rainy          65       70  true   no
7  overcast          64       65  true  yes
8     sunny          72       95 false   no
9     sunny          69       70 false  yes
10    rainy          75       80 false  yes
11    sunny          75       70  true  yes
12 overcast          72       90  true  yes
13 overcast          81       75 false  yes
14    rainy          71       91  true   no

> py <- party(partynode(1, split = partysplit(1, index = 1:3), 
+     kids = list(partynode(2, split = partysplit(3, breaks = 75), 
+         kids = l .... [TRUNCATED] 

> plot(py)

> sp_o <- partysplit(1, index = 1:3)

> sp_h <- partysplit(3, breaks = 75)

> sp_w <- partysplit(4, index = 1:2)

> pn <- partynode(1, split = sp_o, kids = list(partynode(2, 
+     split = sp_h, kids = list(partynode(3, info = "yes"), partynode(4, 
+         info  .... [TRUNCATED] 

> pn
[1] root
|   [2] V1 in (-Inf,1]
|   |   [3] V3 <= 75 *
|   |   [4] V3 > 75 *
|   [5] V1 in (1,2] *
|   [6] V1 in (2, Inf]
|   |   [7] V4 <= 1 *
|   |   [8] V4 > 1 *

> py <- party(pn, WeatherPlay)

> print(py)
[1] root
|   [2] outlook in sunny
|   |   [3] humidity <= 75: yes
|   |   [4] humidity > 75: no
|   [5] outlook in overcast: yes
|   [6] outlook in rainy
|   |   [7] windy in false: yes
|   |   [8] windy in true: no

> predict(py, head(WeatherPlay))
1 2 3 4 5 6 
4 4 5 7 7 8 

> length(py)
[1] 8

> width(py)
[1] 5

> depth(py)
[1] 2

> py[6]
[6] root
|   [7] windy in false: yes
|   [8] windy in true: no

> py2 <- py

> names(py2)
[1] "1" "2" "3" "4" "5" "6" "7" "8"

> names(py2) <- LETTERS[1:8]

> py2
[A] root
|   [B] outlook in sunny
|   |   [C] humidity <= 75: yes
|   |   [D] humidity > 75: no
|   [E] outlook in overcast: yes
|   [F] outlook in rainy
|   |   [G] windy in false: yes
|   |   [H] windy in true: no

> nodeids(py)
[1] 1 2 3 4 5 6 7 8

> nodeids(py, terminal = TRUE)
[1] 3 4 5 7 8

> nodeapply(py, ids = c(1, 7), FUN = function(n) n$info)
$`1`
NULL

$`7`
[1] "yes"


> nodeapply(py, ids = nodeids(py, terminal = TRUE), 
+     FUN = function(n) paste("Play decision:", n$info))
$`3`
[1] "Play decision: yes"

$`4`
[1] "Play decision: no"

$`5`
[1] "Play decision: yes"

$`7`
[1] "Play decision: yes"

$`8`
[1] "Play decision: no"


> predict(py, FUN = function(n) paste("Play decision:", 
+     n$info))
                   1                    2                    3 
 "Play decision: no"  "Play decision: no" "Play decision: yes" 
                   4                    5                    6 
"Play decision: yes" "Play decision: yes"  "Play decision: no" 
                   7                    8                    9 
"Play decision: yes"  "Play decision: no" "Play decision: yes" 
                  10                   11                   12 
"Play decision: yes" "Play decision: yes" "Play decision: yes" 
                  13                   14 
"Play decision: yes"  "Play decision: no" 

> print(py, terminal_panel = function(n) c(", then the play decision is:", 
+     toupper(n$info)))
[1] root
|   [2] outlook in sunny
|   |   [3] humidity <= 75, then the play decision is:
|   |       YES
|   |   [4] humidity > 75, then the play decision is:
|   |       NO
|   [5] outlook in overcast, then the play decision is:
|       YES
|   [6] outlook in rainy
|   |   [7] windy in false, then the play decision is:
|   |       YES
|   |   [8] windy in true, then the play decision is:
|   |       NO

> plot(py[6])

> plot(py, tp_args = list(FUN = function(i) c("Play decision:", 
+     toupper(i))))

> nodeprune(py, 2)

  When sourcing ‘partykit.R’:
Error: no applicable method for ‘nodeids’ applied to an object of class "NULL"
Execution halted