4

R6 class functions are anonymous so profiling information is lost. For example:

library(R6)
library(proftools)

Test <- R6Class("Test",
  public = list(
    fn = function() pause(0.3)
  )
)
obj <- Test$new()

#
# Profile
Rprof(line.profiling=TRUE)
replicate(10, obj$fn())
Rprof(NULL)
png('profile-self.png')
plotProfileCallGraph(readProfileData(), score='self')
dev.off()

gives the following profile information:

profile graph

How can I profile these functions effectively?

Epimetheus
  • 1,119
  • 1
  • 10
  • 19

1 Answers1

2

If you're using a recent version of R-devel (since this commit), it will output obj$fn instead of <Anonymous> in the profiling data. This should be in the next release of R (3.3.0?).

wch
  • 4,069
  • 2
  • 28
  • 36