@@ -24,16 +24,28 @@ bind_fit_components <- function(fit_list, component){
2424
2525}
2626
27- # ' this is a possible generalisation to bind all the elements of multiple gadget.fit objects
28- bind_fit <- function (fit_list , ... ){
27+ # ' @title Combine multiple gadget.fit objects
28+ # ' @description This function combines multiple gadget.fit objects into a single fit object.
29+ # ' An additional column 'id' is added to each element of the resulting list to identify
30+ # ' the individual gadget.fits
31+ # ' @param fit_list A list of multiple gadget.fit objects.
32+ # ' @details
33+ # ' The 'id' column will be taken from names(fit_list). If fit_list has no names, the 'id'
34+ # ' column will be taken from the positions, e.g.,
35+ # ' fit_list = list(a = fit1, b = fit2) will be produces id's of 'a' and 'b', whereas
36+ # ' fit_list = list(fit1, fit2) will produce id's of '1' and '2'
37+ # '
38+ # ' @returns A gadget.fit object
39+ # ' @export
40+ bind_fit <- function (fit_list ){
2941 # initialise an empty list
3042 out <- fit_list [[1 ]]
3143 out [] <- NA
3244 for (i in 1 : length(out )){
3345 if (sum(class(fit_list [[1 ]][[names(out )[i ]]]) == " data.frame" ) == 1 ){
3446 tmp <- sapply(fit_list ,function (x ){x [names(out )[i ]]})
3547 names(tmp ) <- names(fit_list ) # replace with readable model names
36- out [[i ]] <- bind_rows(tmp , .id = " id" )
48+ out [[i ]] <- dplyr :: bind_rows(tmp , .id = " id" )
3749 } else { NULL }}
3850
3951 return (out )
0 commit comments