Memory profiling in R - tools for summarizing

前端 未结 2 2050
时光取名叫无心
时光取名叫无心 2020-12-14 06:39

R has some tools for memory profiling, like Rprofmem(), Rprof() with option \"memory.profiling=TRUE\" and tracemem(). Th

相关标签:
2条回答
  • 2020-12-14 07:09

    Check out profr -- it seems like exactly what you're looking for.

    0 讨论(0)
  • 2020-12-14 07:36

    profvis looks like the the solution to this question.

    It generates an interactive .html file (using htmlwidgets) showing the profiling of your code.

    The introduction vignette is a good guide on its capability.

    Taking directly from the introduction, you would use it like this:

    devtools::install_github("rstudio/profvis")
    library(profvis)
    
    # Generate data
    times <- 4e5
    cols <- 150
    data <- as.data.frame(x = matrix(rnorm(times * cols, mean = 5), ncol = cols))
    data <- cbind(id = paste0("g", seq_len(times)), data)
    profvis({
        data1 <- data   # Store in another variable for this run
    
        # Get column means
        means <- apply(data1[, names(data1) != "id"], 2, mean)
    
        # Subtract mean from each column
        for (i in seq_along(means)) {
            data1[, names(data1) != "id"][, i] <- data1[, names(data1) != "id"][, i] - means[i]
        }
    }, height = "400px")
    

    Which gives

    0 讨论(0)
提交回复
热议问题