varimpact
varimpact copied to clipboard
Fix Issue #6: Add support for single column data
Summary
This PR fixes Issue #6 "Single column in data" by adding comprehensive support for single column data and vector inputs to the varimpact package.
Problem
Previously, the package would throw an error when users tried to analyze single variables:
Error: invalid 'type' (list) of argumentwhen using single columns- Required at least 2 columns in the data argument
- Did not support vector inputs
- Character column conversion had edge cases with single columns
Solution
Changes Made
- Removed 2-column requirement: The main
varimpact()function now accepts single column data - Added vector input support: Vectors are automatically converted to single-column data frames
- Added appropriate warnings: Users are warned when using single variables for analysis
- Fixed character column conversion: Improved handling in
separate_factors_numerics()for single character columns - Added comprehensive tests: New test suite covers all single column scenarios
Code Changes
R/varimpact.R
- Replaced the 2-column requirement with vector input handling and single column support
- Added warning for single variable analysis
- Maintained backward compatibility
R/separate_factors_numerics.R
- Fixed character to factor conversion for single columns
- Used individual column processing to avoid matrix conversion issues
tests/testthat/test-single-column.R
- Added comprehensive test suite for single column scenarios
- Tests vector input, single numeric, single factor, and single character columns
- Includes regression tests to ensure existing functionality still works
Testing
All tests pass, including:
- ✅ Single numeric column support
- ✅ Single factor column support
- ✅ Single character column conversion to factor
- ✅ Vector input conversion to data frame
- ✅ Appropriate warnings for single variable analysis
- ✅ Backward compatibility with existing multi-column functionality
Backward Compatibility
This change is fully backward compatible. All existing code will continue to work exactly as before, but now single column data is also supported.
Addresses
Fixes #6
Example Usage
# Vector input (now supported)
Y <- rbinom(100, 1, 0.5)
X_vector <- rnorm(100)
vim <- varimpact(Y = Y, data = X_vector) # Now works with warning
# Single column data frame (now supported)
X_single <- data.frame(x1 = rnorm(100))
vim <- varimpact(Y = Y, data = X_single) # Now works with warning
# Multiple columns (still works as before)
X_multi <- data.frame(x1 = rnorm(100), x2 = rnorm(100))
vim <- varimpact(Y = Y, data = X_multi) # Works without warning