|
| 1 | +# Package Organization Review and Improvements |
| 2 | + |
| 3 | +## Date: December 4, 2025 |
| 4 | + |
| 5 | +## Summary |
| 6 | + |
| 7 | +This document summarizes the organizational review of the **funtimes** R package and the improvements implemented. |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +## Package Structure Overview |
| 12 | + |
| 13 | +The funtimes package is a collection of functions for time series analysis with the following main categories: |
| 14 | + |
| 15 | +1. **Trend Testing**: `notrend_test()`, `wavk_test()`, `sync_test()`, `WAVK()`, `HVK()`, `ARest()` |
| 16 | +2. **Changepoint Detection**: `mcusum_test()`, `cumsumCPA_test()`, `GombayCPA_test()`, `AuePolyReg_test()` |
| 17 | +3. **Time Series Clustering**: `sync_cluster()`, `CSlideCluster()`, `CWindowCluster()`, `BICC()`, `DR()` |
| 18 | +4. **Granger Causality**: `causality_pred()`, `causality_predVAR()`, `ccf_boot()` |
| 19 | +5. **Distribution Comparison**: `tails_i()`, `tails_q()` |
| 20 | +6. **Estimation**: `beales()`, `r_crit()` |
| 21 | +7. **Utilities**: `purity()` |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +## Issues Identified and Resolved |
| 26 | + |
| 27 | +### 1. ✅ Undocumented Internal Helper Functions |
| 28 | + |
| 29 | +**Issue**: Three files contained internal helper functions without proper documentation headers: |
| 30 | +- `fun_cusum.R` - CUSUM-related helpers |
| 31 | +- `fun_trust.R` - TRUST algorithm helpers |
| 32 | +- `fun_causality.R` - Causality testing helpers |
| 33 | + |
| 34 | +**Resolution**: Added comprehensive internal documentation headers to all three files, including: |
| 35 | +- Purpose and context |
| 36 | +- List of functions contained |
| 37 | +- References to relevant papers |
| 38 | +- `@keywords internal` and `@noRd` tags |
| 39 | + |
| 40 | +### 2. ✅ Undocumented Modified VAR Functions |
| 41 | + |
| 42 | +**Issue**: Three files (`VAR.R`, `VARselect.R`, `toMlm.R`) are modified copies from the `vars` package, but the modifications were not well-documented. |
| 43 | + |
| 44 | +**Resolution**: Enhanced documentation headers explaining: |
| 45 | +- Origin (vars package by Bernhard Pfaff) |
| 46 | +- Why modifications exist (unmerged pull request from 2021) |
| 47 | +- Key modifications (lag.restrict parameter, restricted VAR support) |
| 48 | +- Link to original pull request |
| 49 | + |
| 50 | +### 3. ✅ Misc Directory Organization |
| 51 | + |
| 52 | +**Issue**: The `misc/` directory contained a mix of experimental, archived, and old code without documentation. |
| 53 | + |
| 54 | +**Resolution**: Created `misc/README.md` documenting: |
| 55 | +- **TopoCBN.R**: Archived function removed in v8.2 due to TDA dependency |
| 56 | +- **causality_predVAR_v0.R**: Old version kept for reference |
| 57 | +- **CRAD files**: Removed (experimental approach abandoned) |
| 58 | + |
| 59 | +--- |
| 60 | + |
| 61 | +## Recommendations for Future Improvements |
| 62 | + |
| 63 | +### High Priority |
| 64 | + |
| 65 | +1. **Remove Defunct Functions** (noted in README "Future work") |
| 66 | + - The defunct function files (`i.tails.R`, `q.tails.R`, `mcusum.test.R`, `notrend.test.R`, `sync.test.R`, `sync.cluster.R`, `wavk.test.R`) only contain `.Defunct()` calls |
| 67 | + - Consider removing these entirely in next major version |
| 68 | + - Current approach is correct for graceful deprecation cycle |
| 69 | + |
| 70 | +2. **Complete causality_pred() Documentation** (noted in README "Future work") |
| 71 | + - Add detailed description of statistics computed (MSEt, MSEcor, OOSF, EN) |
| 72 | + - Reference Clark & McCracken papers more explicitly in documentation |
| 73 | + |
| 74 | +3. **✅ CRAD Implementation Decision** (RESOLVED) |
| 75 | + - CRAD files have been removed (experimental approach abandoned) |
| 76 | + - No Python dependencies remain in the package |
| 77 | + |
| 78 | +### Medium Priority |
| 79 | + |
| 80 | +4. **Consider Creating Internal Package Documentation** |
| 81 | + - Add a vignette or article on package internals for developers |
| 82 | + - Document the relationship between helper functions and exported functions |
| 83 | + - Explain the modified VAR implementation strategy |
| 84 | + |
| 85 | +5. **File Naming Consistency** |
| 86 | + - Most functions use underscores (e.g., `wavk_test.R`) |
| 87 | + - Helper files use different conventions (`fun_*.R`) |
| 88 | + - Consider prefixing internal files more consistently (e.g., `internal_cusum.R`) |
| 89 | + |
| 90 | +6. **Code Organization by Category** |
| 91 | + - Consider organizing R files into subdirectories by function category: |
| 92 | + - `R/trend/` - trend testing functions |
| 93 | + - `R/changepoint/` - changepoint detection |
| 94 | + - `R/clustering/` - clustering methods |
| 95 | + - `R/causality/` - causality testing |
| 96 | + - `R/internal/` - helper functions |
| 97 | + - However, R package structure typically keeps all `.R` files in `R/` directory, so this may not be necessary |
| 98 | + |
| 99 | +### Low Priority |
| 100 | + |
| 101 | +7. **Old Release Archives** |
| 102 | + - `oldrel/` directory contains package tarballs from v1.0 to v7.0 |
| 103 | + - These can be accessed from CRAN archives |
| 104 | + - Consider removing to reduce repository size |
| 105 | + |
| 106 | +8. **Add CITATION File** |
| 107 | + - Package has extensive references but no `inst/CITATION` file |
| 108 | + - Would help users cite the package properly |
| 109 | + |
| 110 | +9. **Update Copyright/License Information** |
| 111 | + - Document that VAR-related functions are derived from `vars` package |
| 112 | + - Ensure GPL compatibility is maintained |
| 113 | + |
| 114 | +--- |
| 115 | + |
| 116 | +## Package Strengths |
| 117 | + |
| 118 | +1. **Excellent Documentation**: Most exported functions have comprehensive roxygen2 documentation with examples |
| 119 | +2. **Good Deprecation Practice**: Proper use of deprecated → defunct lifecycle |
| 120 | +3. **Well-Maintained**: Active development with clear version history in README |
| 121 | +4. **Comprehensive Vignettes**: Three informative vignettes for major use cases |
| 122 | +5. **Proper Citations**: Good use of Rdpack for inserting references |
| 123 | + |
| 124 | +--- |
| 125 | + |
| 126 | +## Conclusion |
| 127 | + |
| 128 | +The funtimes package is generally well-organized for a collection of diverse time series analysis functions. The improvements implemented today enhance the internal documentation and make the codebase more maintainable. The remaining recommendations are mostly cleanup tasks that can be addressed in future releases as the package continues to evolve. |
0 commit comments