Error dataset & object not found in package 'ipred'

heart_failure_clinical <-read.csv(file.choose(),header = TRUE)
heart_failure_clinical

library(ipred)
library(survival)
library(rpart)
library(party)

Brier score in Model ipred

data("heart_failure_clinical", package = "ipred")
gbag <- bagging(Surv(time,DEATH_EVENT) ~., data=heart_failure_clinical, nbagg = 299, coob=TRUE)
print(gbag)

Brier score in Model rpart (Survival Trees)

data("heart_failure_clinical", package = "ipred")
gbag <- bagging(Surv(time,DEATH_EVENT) ~., data=heart_failure_clinical, model = rpart, nbagg = 299, coob=TRUE)
print(gbag)

Brier score in Model ctree (Survival Trees)

data("heart_failure_clinical", package = "ipred")
gbag <- bagging(Surv(time,DEATH_EVENT) ~., data=heart_failure_clinical, model = ctree, nbagg = 299, coob=TRUE)
print(gbag)

Brier score in Model linear

data("heart_failure_clinical", package = "ipred")
gbag <- bagging(Surv(time,DEATH_EVENT) ~., data=heart_failure_clinical, model = lm, nbagg = 299, coob=TRUE)
print(gbag)

function "rsurv" (Simulate Survival Data)

library("survival")
heart_failure_clinical <- rsurv(299, model= "C")
coxph(Surv(time,DEATH_EVENT) ~ ., data=heart_failure_clinical)

> library(ipred)
> library(survival)
> library(rpart)
> library(party)
> data("heart_failure_clinical", package = "ipred")
**Warning message:**
**In data("heart_failure_clinical", package = "ipred") :**
**  data set ‘heart_failure_clinical’ not found**
> gbag <- bagging(Surv(time,DEATH_EVENT) ~., data=heart_failure_clinical, nbagg = 299, coob=TRUE)
> print(gbag) 

Bagging survival trees with 299 bootstrap replications 

Call: bagging.data.frame(formula = Surv(time, DEATH_EVENT) ~ ., data = heart_failure_clinical, 
    nbagg = 299, coob = TRUE)

Out-of-bag estimate of Brier's score:  0.1452
> # Brier score in Model rpart (Survival Trees)
> data("heart_failure_clinical", package = "ipred")
**Warning message:**
**In data("heart_failure_clinical", package = "ipred") :**
**  data set ‘heart_failure_clinical’ not found**
> gbag <- bagging(Surv(time,DEATH_EVENT) ~., data=heart_failure_clinical, model = rpart, nbagg = 299, coob=TRUE)
> print(gbag)  

Bagging survival trees with 299 bootstrap replications 

Call: bagging.data.frame(formula = Surv(time, DEATH_EVENT) ~ ., data = heart_failure_clinical, 
    model = rpart, nbagg = 299, coob = TRUE)

Out-of-bag estimate of Brier's score:  0.1461 

> # Brier score in Model ctree (Survival Trees)
> data("heart_failure_clinical", package = "ipred")
**Warning message:**
**In data("heart_failure_clinical", package = "ipred") :**
**  data set ‘heart_failure_clinical’ not found**
> gbag <- bagging(Surv(time,DEATH_EVENT) ~., data=heart_failure_clinical, model = ctree, nbagg = 299, coob=TRUE)
> print(gbag)        

Bagging survival trees with 299 bootstrap replications 

Call: bagging.data.frame(formula = Surv(time, DEATH_EVENT) ~ ., data = heart_failure_clinical, 
    model = ctree, nbagg = 299, coob = TRUE)

Out-of-bag estimate of Brier's score:  0.144 

> # Brier score in Model linear
> data("heart_failure_clinical", package = "ipred")
**Warning message:**
**In data("heart_failure_clinical", package = "ipred") :**
**  data set ‘heart_failure_clinical’ not found**
> gbag <- bagging(Surv(time,DEATH_EVENT) ~., data=heart_failure_clinical, model = lm, nbagg = 299, coob=TRUE)
> print(gbag)        

Bagging survival trees with 299 bootstrap replications 

Call: bagging.data.frame(formula = Surv(time, DEATH_EVENT) ~ ., data = heart_failure_clinical, 
    model = lm, nbagg = 299, coob = TRUE)

Out-of-bag estimate of Brier's score:  0.1446 

> library("survival")
> heart_failure_clinical <- rsurv(299, model= "C")
> coxph(Surv(time,DEATH_EVENT) ~ ., data=heart_failure_clinical)
**Error in Surv(time, DEATH_EVENT) : object 'DEATH_EVENT' not found**
> 

most of your code works because heart_failure_clinical is a data.frame you load from ipred and it has DEATH_EVENT in it.

however towards the bottom; on this line

> library("survival")
> heart_failure_clinical <- rsurv(299, model= "C")

you entirely change what heart_failure_clinical contains; it no longer has 'DEATH_EVENT'

Thank you very much.