Description
Optimize loops in R/MappedDataTimeProfile.R by replacing them with vectorized operations for improved performance.
Current Implementation Issues
Loop in scaleDataForSecondaryAxis() (Lines 252-263)
- Iterates through scaling-relevant mappings one by one
- Can be replaced with vectorized operations
Loop in dataForPlot() (Lines 323-345)
- Iterates through aesthetics checking for negative values
- Inefficient for datasets with many aesthetics
- Repeatedly accesses data frame columns in loop
Loop in checkForCallAesthetics() (Lines 365-389)
- Iterates through scaling-relevant mappings sequentially
- Similar pattern to
scaleDataForSecondaryAxis()
Nested loop in setyLimits() (Lines 410-429)
- Iterates through aesthetics within axis loop
- Double iteration pattern that can be optimized
Suggested Implementation
scaleDataForSecondaryAxis(): Use lapply() or vapply() with vectorized scaling operations
dataForPlot(): Use vectorized column checking with any() and all() functions across aesthetics
checkForCallAesthetics(): Refactor to use list operations instead of explicit loops
setyLimits(): Flatten nested structure or use expand.grid() approach
Expected Benefits
- Faster time profile plot generation
- Better performance with large time-series datasets
- Reduced memory allocations during plotting
Implementation Notes
Files to Modify
R/MappedDataTimeProfile.R
Testing
- Run existing time profile tests
- Test with various secondary axis configurations
- Verify scaling calculations remain accurate
- Test with large time-series datasets
Description
Optimize loops in
R/MappedDataTimeProfile.Rby replacing them with vectorized operations for improved performance.Current Implementation Issues
Loop in
scaleDataForSecondaryAxis()(Lines 252-263)Loop in
dataForPlot()(Lines 323-345)Loop in
checkForCallAesthetics()(Lines 365-389)scaleDataForSecondaryAxis()Nested loop in
setyLimits()(Lines 410-429)Suggested Implementation
scaleDataForSecondaryAxis(): Uselapply()orvapply()with vectorized scaling operationsdataForPlot(): Use vectorized column checking withany()andall()functions across aestheticscheckForCallAesthetics(): Refactor to use list operations instead of explicit loopssetyLimits(): Flatten nested structure or useexpand.grid()approachExpected Benefits
Implementation Notes
Files to Modify
R/MappedDataTimeProfile.RTesting