A comprehensive R package for profiling and analyzing the performance of R scripts. This tool provides detailed metrics on execution time and memory usage for different steps of your R code, along with interactive HTML reports.
- Step-by-step Profiling: Track execution time and memory usage for individual code blocks
- Interactive HTML Reports: Generate beautiful, interactive reports with visualizations
- Memory Usage Analysis: Monitor memory consumption for each step
- Easy Integration: Simple function calls to profile your existing R code
- Dependency Management: Automatically installs required packages
- Detailed Documentation: Comprehensive function reference and examples
- Demo Script: Ready-to-run example showing the tool in action
# Install from GitHub
if (!require("devtools")) install.packages("devtools")
devtools::install_github("username/profiling")
# Or use the script directly
source("profiling.R")Try out the profiling tool with the included demo script demo.R
This will:
- Profile several example operations
- Generate an interactive HTML report
- Open the report in your default browser
# Initialize profiling
.init_profiling(script_name = "my_analysis.R")
# Profile a code block
profile_code("data_loading", {
# Your data loading code here
data <- read.csv("data.csv")
})
# Profile another step
profile_code("data_processing", {
# Your processing code here
processed_data <- transform(data, new_col = old_col * 2)
})
# Generate report
generate_profiling_report(show_report = TRUE)For complete documentation of all functions, parameters, and advanced usage, see DOCUMENTATION.md.
.init_profiling(...)- Initialize the profiling environmentprofile_code(step_name, expr)- Profile a code block (recommended for most use cases)generate_profiling_report(...)- Generate an HTML report
.start_profiling_step(step_name)- Manually start profiling a step.end_profiling_step(step_name)- Manually end profiling a step
For detailed parameter descriptions and examples, see the full documentation.
The generated HTML report includes:
- Summary Statistics: Total time, average step time, peak memory usage
- Interactive Visualizations:
- Execution time by step
- Memory usage over time
- Detailed metrics table
- Export Options: Save report as HTML or print to PDF
- Responsive Design: Works on desktop and mobile devices
A ready-to-run demo script is included (demo.R) that demonstrates:
- Basic profiling of code blocks
- Nested profiling operations
- Report generation and viewing
To run the demo:
source("demo.R")For questions or issues, please open an issue.
The script will automatically install these packages if not already installed:
- pryr - Memory usage tracking
- tictoc - Precise timing
- knitr/kableExtra - Report generation
- ggplot2/plotly - Interactive visualizations
- DT - Interactive tables
- gridExtra - Layout management
- Profile early and often to identify performance bottlenecks
- Keep step names descriptive but concise
- Focus on profiling the most time-consuming parts of your code
- Compare profiles before and after optimization to measure improvements
MIT
