Performance suggestions in R -


i have piece of code:

library("go.db") lookparents <- function(x) {   parents <- subset(yy[x][[1]], labels(yy[x][[1]])=="is_a")   (parent in parents) {     m[index,1] <<- term(x)     m[index,2] <<- term(parent)     m[index,3] <<- -log2(go_freq[x,1]/go_freq_all)     m[index,4] <<- log2(go1_freq2[x])     m[index,5] <<- x     m[index,6] <<- parent     index <<- index + 1   }   if (is.null(parents)) {     return(c())   } else {     return(parents)   } }  gettreemap <- function(golist, xx, m) {   print(paste("input list has",length(golist), "terms", sep=" "))   count <- 1   (go in golist) {     parents <- lookparents(go)     if (count %% 100 == 0) {       print(count)     }     while (length(parents) != 0) {       x <- parents[1]       parents <- parents[-1]       parents <- c(lookparents(x), parents)     }     count <- count + 1   } }  xx <- c(as.list(gobpancestor), as.list(goccancestor), as.list(gomfancestor)) go1_freq2 <- table(as.character(unlist(xx[go1]))) xx <- c(as.list(gobpparents), as.list(goccparents), as.list(gomfparents))  m <- as.data.frame(matrix(nrow=1,ncol=6)) m[1,] <- c("all", "null", 0, 0, "null","null") ##biological processes index <- 2 gettreemap(bp, xx, m) 

but slow. bp vector. have performance suggestions apply? make run faster, that's can @ moment.

i suggest following improvements:

  • add functions rprofile.site , compile them using cmpfun
  • use foreach , dopar instead of normal for
  • always delete variables don't need anymore , call garbage collector

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -