Skip to content

Remove birthweight dataset references and fix 4 test failures#3

Closed
Copilot wants to merge 2 commits intomasterfrom
copilot/remove-birthweight-references
Closed

Remove birthweight dataset references and fix 4 test failures#3
Copilot wants to merge 2 commits intomasterfrom
copilot/remove-birthweight-references

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 25, 2026

The birthweight dataset was replaced by cachar_sample but leftover test references and several unrelated test bugs were causing 10 CI failures.

Changes

  • Deleted obsolete birthweight test (test-calc-risk-diff.R): Removed test_that("calc_risk_diff works with package birthweight data", ...) entirely — dataset no longer exists in the package.

  • Fixed create_convergence_challenge_data() (test-calc-risk-diff.R): data.frame() evaluates arguments in the calling environment, not incrementally, so exposure was not in scope when computing outcome_prob. Extracted both as local variables before the data.frame() call:

    # Before (broken): exposure not in scope inside data.frame()
    data.frame(
      exposure = factor(c(rep("No", n*0.8), rep("Yes", n*0.2))),
      outcome_prob = ifelse(exposure == "Yes", 0.85, 0.05),  # error: object 'exposure' not found
      ...
    )
    
    # After: pre-compute outside data.frame()
    exposure <- factor(c(rep("No", n*0.8), rep("Yes", n*0.2)))
    outcome_prob <- ifelse(exposure == "Yes", 0.85, 0.05)
    data.frame(exposure = exposure, outcome = rbinom(n, 1, outcome_prob), ...)
  • Fixed boundary detection SE test (test-boundary-detection-enhanced.R): n=50 with 1 confounder wasn't pushing SE/coefficient ratio above the detection threshold. Reduced to n=30 and added confounders x1x4 to overparameterize the model and reliably trigger large_standard_errors.

  • Fixed sex-stratified result check (test-calc-risk-diff.R): When a stratum row is missing, male_result$rd returns numeric(0), making if (!is.na(...)) throw "argument is of length zero". Added nrow() > 0 guard:

    if (nrow(male_result) > 0 && !is.na(male_result$rd)) expect_true(male_result$rd > 0)
Original prompt

Remove All Birthweight Dataset References and Fix Remaining Test Failures

The package previously contained a birthweight dataset that was replaced with cachar_sample synthetic data. However, leftover references to birthweight remain in the codebase and are causing test failures.

10 Test Failures to Fix:

Primary Issues:

  1. Birthweight dataset reference (test-calc-risk-diff.R:636)

    • Test: "calc_risk_diff works with package birthweight data"
    • Error: object 'birthweight' not found
    • Solution: Delete this entire test block (lines ~631-651) - it's obsolete
  2. create_convergence_challenge_data() has a variable reference error (test-calc-risk-diff.R:400)

    • Error: object 'exposure' not found
    • Problem: Function tries to use exposure in a piped operation before it's created in the dataframe
    • Solution: Use proper column reference syntax within mutate() or create exposure first
  3. Large standard errors boundary test not triggering detection (test-boundary-detection-enhanced.R:103)

    • Test: "boundary detection handles large standard errors"
    • Failure: boundary_large_se$boundary_type doesn't match expected values
    • Solution: Add more confounders (x1, x2, x3, x4) and use smaller n to push SE/coef ratio > 2
  4. Sex-stratified results returning empty dataframes (test-calc-risk-diff.R:606)

    • Test: "calc_risk_diff shows expected sex differences in tobacco use patterns"
    • Error: argument is of length zero when accessing male_result$rd
    • Solution: Add defensive check for empty results: if (nrow(male_result) > 0) { ... }

All References to Remove:

Search across entire repo for "birthweight" and replace/remove:

  • Test files
  • Documentation files
  • Comments
  • R data files
  • Examples

Expected Outcome:

  • All 10 test failures resolved
  • 0 test failures, 588 passing tests
  • All birthweight references completely removed
  • Package passes R CMD check without errors

This pull request was created from Copilot chat.


💡 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.

…nction, fix boundary detection, fix sex-stratified check

Co-authored-by: jackmurphy2351 <120122776+jackmurphy2351@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove all birthweight dataset references and fix test failures Remove birthweight dataset references and fix 4 test failures Feb 25, 2026
@jackmurphy2351 jackmurphy2351 marked this pull request as ready for review February 25, 2026 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants