profvis

repository·main·Indexed 43 days ago

https://github.com/r-lib/profvis

A tool for visualizing code profiling data from R that generates an interactive web page for exploring performance data via the profvis() function.

Tokens
762
Snippets
4
Records
5
Agent score
5%

What's inside profvis

  1. Save and view profvis htmlwidgets

    main

    The profvis() function returns an htmlwidget. If you assign the result of profvis() to a variable, it will not open the browser immediately. You can view the interactive profile later by typing the variable name in the R console or by calling print() on the object.

    p <- profvis(f())
    
    # To view the interactive visualizer later:
    p
    # or
    print(p)
  2. Interpret profvis report comments and check results

    main

    The profvis report includes summary sections that provide context on the health of the package being profiled. These sections include:

    • R CMD check results: Summarizes the number of errors, warnings, and notes found during an R CMD check run.
    • revdepcheck results: Summarizes the results of checking reverse dependencies. It reports how many reverse dependencies were checked, how many new problems were identified, and how many packages failed the check. It compares results between CRAN and development versions.
    • New problems: A specific list of new failures identified in reverse dependencies, typically showing the package name and a link to a patch if one was submitted.
  3. Profile and visualize R code with profvis()

    main

    To profile a piece of code, wrap the expression you want to analyze inside the profvis() function. By default, profvis() will automatically open an interactive web-based visualizer in your default web browser to explore the profiling data.

    library(profvis)
    
    f <- function() {
      pause(0.1)
      g()
      h()
    }
    
    # Wrap the expression to be profiled in profvis()
    profvis(f())
  4. Troubleshoot 'object not found' errors in profvis vignette checks

    main

    When running profvis within an R Markdown vignette (e.g., during R CMD check or vignette re-building), you may encounter errors where objects created inside the profvis() call are not accessible in the subsequent code chunks.

    This typically happens because profvis captures the execution environment. If you attempt to use a result variable (like res1) outside the profvis({...}) block, the object may not be found in the global or vignette environment.

    Symptoms:

    • ERROR: checking running R code from vignettes
    • Error: object 'res1' not found
    • NOTE: checking re-building of vignette outputs
    # Example of code that might trigger this error in a vignette
    profvis({
      res1 = ft %>% select_fst(Species, Sepal.Length, Sepal.Width, Petal.Length) %>% dplyr::select(-Petal.Length)
    })
    
    # This line fails because 'res1' was not properly exported from the profvis environment
    setequal(res1, res2)