Skip to content

Commit 3b0e24d

Browse files
committed
bind_fit exported and documented
1 parent a7a252f commit 3b0e24d

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
export("%>%")
44
export(add_g3_attributes)
5+
export(bind_fit)
56
export(bind_fit_components)
67
export(estimate_weights)
78
export(estimate_weights_adist)

R/g3_fit_combine.R

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

man/bind_fit.Rd

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)