Try replacing
x <- as.matrix(subset(d, select=Cs(rx, sex, age, obstruct, perfor, adhere, surg)))
with
x <- model.matrix( ~ rx + sex + age + obstruct + perfor + adhere + surg - 1, d)
The latter will convert the convert the factor rx
to numeric dummy variables in the matrix x
.