@@ -146,32 +146,9 @@ combine_all_mrresults <- function(
146146 het <- het [, c(" id.exposure" , " id.outcome" , " method" , " Q" , " Q_df" , " Q_pval" )]
147147
148148 # Convert all factors to character
149- # lapply(names(Res), FUN=function(x) class(Res[,x]))
150- Class <- unlist(lapply(names(res ), FUN = function (x ) class(res [, x ])))
151- if (any(Class == " factor" )) {
152- Pos <- which(unlist(lapply(names(res ), FUN = function (x ) class(res [, x ]))) == " factor" )
153- for (i in seq_along(Pos )) {
154- res [, Pos [i ]] <- as.character(res [, Pos [i ]])
155- }
156- }
157-
158- # lapply(names(Het), FUN=function(x) class(Het[,x]))
159- Class <- unlist(lapply(names(het ), FUN = function (x ) class(het [, x ])))
160- if (any(Class == " factor" )) {
161- Pos <- which(unlist(lapply(names(het ), FUN = function (x ) class(het [, x ]))) == " factor" )
162- for (i in seq_along(Pos )) {
163- het [, Pos [i ]] <- as.character(het [, Pos [i ]])
164- }
165- }
166-
167- # lapply(names(Sin), FUN=function(x) class(Sin[,x]))
168- Class <- unlist(lapply(names(sin ), FUN = function (x ) class(sin [, x ])))
169- if (any(Class == " factor" )) {
170- Pos <- which(unlist(lapply(names(sin ), FUN = function (x ) class(sin [, x ]))) == " factor" )
171- for (i in seq_along(Pos )) {
172- sin [, Pos [i ]] <- as.character(sin [, Pos [i ]])
173- }
174- }
149+ res [] <- lapply(res , function (x ) if (is.factor(x )) as.character(x ) else x )
150+ het [] <- lapply(het , function (x ) if (is.factor(x )) as.character(x ) else x )
151+ sin [] <- lapply(sin , function (x ) if (is.factor(x )) as.character(x ) else x )
175152
176153 sin <- sin [grep(" [:0-9:]" , sin $ SNP ), ]
177154 sin $ method <- " Wald ratio"
@@ -185,10 +162,11 @@ combine_all_mrresults <- function(
185162 names(sin )[names(sin ) == " method" ] <- " Method"
186163
187164 res <- merge(res , het , by = c(" id.outcome" , " id.exposure" , " Method" ), all.x = TRUE )
188- res <- plyr :: rbind.fill (
189- res ,
190- sin [, c( " exposure " , " outcome " , " id.exposure " , " id.outcome " , " SNP " , " b " , " se " , " pval " , " Method " )]
165+ res <- data.table :: rbindlist (
166+ list ( res , sin [, c( " exposure " , " outcome " , " id.exposure " , " id.outcome " , " SNP " , " b " , " se " , " pval " , " Method " )]) ,
167+ fill = TRUE , use.names = TRUE
191168 )
169+ data.table :: setDF(res )
192170
193171 if (ao_slc ) {
194172 ao <- available_outcomes()
0 commit comments