Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When and why does profvis() show "Sources not available"?

Tags:

r

profiling

I am profiling R code a lot, and make heavy use of profvis().

For some functions, the top half of the browser window shows the source, and sometimes it doesn't. I can't make out when that is the case, it seems random to me.

Does anyone know when and why profvis can't show the code in the top window? One situation where it happens is this piece of code:

simulation <- function(p=1e4, n=100){
  df <- list()
  for(i in 1:p){  # simulate p columns of data
    df[[paste0("Var", i)]] <- rnorm(n)
  }
  df <- as.data.fame(df)

  return(apply(df, 2, mean))
}

profvis(simulation())

profvis

like image 850
Alexander Engelhardt Avatar asked Jul 23 '16 14:07

Alexander Engelhardt


1 Answers

When there is only one function() in profvis(), nothing is in upper part of Frame graph. I think the reason is that a function of highlighting a bar at base of graph is unnecessary.

Example code:

library(profvis)

simulation <- function(p=1e4, n=100){
  df <- list()
  for(i in 1:p){  # simulate p columns of data
    df[[paste0("Var", i)]] <- rnorm(n)
  }
  df <- as.data.frame(df)  
  return(apply(df, 2, mean))
}

profvis(simulation())   # When only one function() is, the source isn't shown.

profvis({               # When there are more than two function(), source is shown.
  simulation()
  sum(iris[,1])
})
like image 160
cuttlefish44 Avatar answered Sep 21 '22 05:09

cuttlefish44