Add support for logical outcome variables in create_IV()
Problem
Currently, the create_IV() function does not accept logical outcome variables and only works with numeric binary variables (0 or 1). When users try to pass a logical column (TRUE/FALSE) as the outcome variable, the function fails with an error.
Solution
This PR adds support for logical outcome variables by:
- Detecting when the outcome variable is logical
- Automatically converting logical values to numeric binary values (TRUE → 1, FALSE → 0)
- Maintaining the validation check that ensures all values are 0 or 1 after conversion
Implementation Details
The changes are minimal and focused:
- Added a check for logical type of the outcome variable
- Added automatic conversion using
as.numeric() - Updated the function documentation to clarify that logical variables are now accepted
Example usage that now works:
# This now works with the changes
sq_data %>%
dplyr::mutate(outcome_logical = Workweek_span > 40) %>% # Logical TRUE/FALSE
create_IV(outcome = "outcome_logical",
predictors = c("Email_hours", "Meeting_hours"),
return = "summary")
Fixes #240.
[!WARNING]
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
_https._tcp.esm.ubuntu.com
- Triggering command:
/usr/lib/apt/methods/https(dns block)_https._tcp.motd.ubuntu.com
- Triggering command:
/usr/lib/apt/methods/https(dns block)cloud.r-project.org
- Triggering command:
/usr/lib/R/bin/exec/R -e install.packages(c('dplyr',~+~'tidyr',~+~'tidyselect',~+~'magrittr',~+~'purrr',~+~'reshape2',~+~'ggplot2',~+~'ggrepel',~+~'scales',~+~'htmltools',~+~'markdown',~+~'rmarkdown',~+~'networkD3',~+~'DT',~+~'tidytext',~+~'ggraph',~+~'igraph',~+~'proxy',~+~'ggwordcloud',~+~'data.table'),~+~repos='REDACTED',~+~lib='~/R/library')(dns block)esm.ubuntu.com
- Triggering command:
/usr/lib/apt/methods/https(dns block)motd.ubuntu.com
- Triggering command:
/usr/lib/apt/methods/https(dns block)If you need me to access, download, or install something from one of these locations, you can either:
- Configure Actions setup steps to set up my environment, which run before the firewall is enabled
- Add the appropriate URLs or hosts to my firewall allow list
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
@copilot please add a test for create_IV() to check that there are no errors if a logical value is passed to outcome.
@copilot please add a test for
create_IV()to check that there are no errors if a logical value is passed tooutcome.
I've added a test for create_IV() in f070482 to verify it properly handles logical outcome variables. The test confirms that:
- No errors occur when passing a logical column to the
outcomeparameter - The function produces the expected data frame output
- Results are consistent between logical and numeric binary inputs
The test uses dplyr::mutate(outcome_logical = Workweek_span > 40) to create a logical TRUE/FALSE variable and passes it to create_IV().
[!WARNING]
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
cdn.fwupd.org
- Triggering command:
/usr/bin/fwupdmgr refresh(dns block)cloud.r-project.org
- Triggering command:
/usr/lib/R/bin/exec/R --no-echo --no-restore -e install.packages(c('devtools',~+~'testthat',~+~'dplyr',~+~'magrittr'),~+~repos='REDACTED',~+~lib='~/R/library')(dns block)esm.ubuntu.com
- Triggering command:
/usr/lib/apt/methods/https(dns block)If you need me to access, download, or install something from one of these locations, you can either:
- Configure Actions setup steps to set up my environment, which run before the firewall is enabled
- Add the appropriate URLs or hosts to my firewall allow list
@copilot please mentioned in the royxgen documentation of the 'outcome' argument for create_IV() that logical values are automatically coerced to numeric. Update the corresponding .Rd file as well.
@copilot please mentioned in the royxgen documentation of the 'outcome' argument for
create_IV()that logical values are automatically coerced to numeric. Update the corresponding.Rdfile as well...
I've updated the .Rd documentation file in commit f4a95d7 to align with the previously updated Roxygen documentation. The outcome parameter documentation now specifies that logical variables are automatically coerced to numeric (TRUE to 1, FALSE to 0).
Looking good - merging PR now.