, do.call , , . , ( cox rms-):
> model <- cph(Surv(Time, Status == "Cardiovascular") ~
+ Group + rcs(Age, 3) + cluster(match_group),
+ data=full_df,
+ x=TRUE, y=TRUE)
> system.time(s_reg <- summary(object = model))
user system elapsed
0.00 0.02 0.03
> system.time(s_dc <- do.call(summary, list(object = model)))
user system elapsed
282.27 0.08 282.43
> nrow(full_df)
[1] 436305
While the solution data.tableis a great approach to the above, it does not contain full functionality do.call, and so I decided to share my function fastDoCall- a modification of Hadley Wickhams suggested hack on the mailing list R. It is available in version 1.0 of the Gmisc package (not yet released on CRAN, but you can find it here ). Reference indicator:
> system.time(s_fc <- fastDoCall(summary, list(object = model)))
user system elapsed
0.03 0.00 0.06
The full code for the function is given below:
fastDoCall <- function(what, args, quote = FALSE, envir = parent.frame()){
if (quote)
args <- lapply(args, enquote)
if (is.null(names(args))){
argn <- args
args <- list()
}else{
argn <- lapply(names(args)[names(args) != ""], as.name)
names(argn) <- names(args)[names(args) != ""]
argn <- c(argn, args[names(args) == ""])
args <- args[names(args) != ""]
}
if (class(what) == "character"){
if(is.character(what)){
fn <- strsplit(what, "[:]{2,3}")[[1]]
what <- if(length(fn)==1) {
get(fn[[1]], envir=envir, mode="function")
} else {
get(fn[[2]], envir=asNamespace(fn[[1]]), mode="function")
}
}
call <- as.call(c(list(what), argn))
}else if (class(what) == "function"){
f_name <- deparse(substitute(what))
call <- as.call(c(list(as.name(f_name)), argn))
args[[f_name]] <- what
}else if (class(what) == "name"){
call <- as.call(c(list(what, argn)))
}
eval(call,
envir = args,
enclos = envir)
}