Skip to content

Fix Covy#29

Merged
fbargaglistoffi merged 7 commits intofbargaglistoffi:masterfrom
charliewang123:master
Mar 8, 2026
Merged

Fix Covy#29
fbargaglistoffi merged 7 commits intofbargaglistoffi:masterfrom
charliewang123:master

Conversation

@charliewang123
Copy link
Copy Markdown
Contributor

  • Reordered parameters: N, Y, W, G → N, W, G, Y

  • Removed varzero = NULL initialization

  • Moved pairs computation inside the sample size check and pre-allocated variab = numeric(nrow(pairs)) instead of growing with c()

  • Cached pij() result in pij_val to avoid calling it twice per iteration

  • Removed unnecessary sum() wrapping a scalar expression

  • Updated man/Covy.Rd

  • Updated tests to fix the parameter passing in the Covy() call

  • Added N back to the signature and the docs

Copilot AI review requested due to automatic review settings March 5, 2026 00:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes and optimizes the Covy() covariance estimator by reordering its arguments, reducing repeated computations, and improving how pairwise terms are accumulated, with corresponding doc/test updates.

Changes:

  • Reordered Covy() parameters to N, w1, g1, w2, g2, W, G, Y, p, Ne, Ne_list and updated documentation accordingly.
  • Refactored Covy() internals to pre-allocate variab and cache pij() results to avoid duplicate calls.
  • Updated the Covy() unit test to match the new argument order.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
R/Covy.R Reorders signature and refactors pairwise computation to avoid repeated calls and vector growth.
man/Covy.Rd Updates usage/argument order to match the new Covy() signature.
tests/testthat/test-Covy.R Updates the Covy() invocation to align with the reordered parameters.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Ne_list <- list(2,1,4,3,6,5)

c0010 <- Covy(0,0,1,0, N, Y, W, G, p, Ne, Ne_list)
c0010 <- Covy(N = N, 0,0,1,0, W, G, Y, p, Ne, Ne_list)
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test call mixes a named argument (N = N) with positional arguments. This makes the test brittle to future signature changes (especially since this PR is about reordering args) and harder to read. Prefer passing all arguments by name (or pass N positionally as the first argument).

Suggested change
c0010 <- Covy(N = N, 0,0,1,0, W, G, Y, p, Ne, Ne_list)
c0010 <- Covy(N, 0,0,1,0, W, G, Y, p, Ne, Ne_list)

Copilot uses AI. Check for mistakes.
Comment thread R/Covy.R
Comment on lines +32 to 38
pairs <- expand.grid.unique(which(W == w1 & G == g1),
which(W == w2 & G == g2),
include.equals = FALSE)

# Initialize
variab = numeric(nrow(pairs))

Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pairs creation and variab initialization are inside the if (...) { block but are not indented like the rest of the block. This makes it easy to misread the control flow and inconsistent with the surrounding style in this repo (e.g., other functions indent block bodies). Please indent these lines to clearly show they are guarded by the sample-size check.

Suggested change
pairs <- expand.grid.unique(which(W == w1 & G == g1),
which(W == w2 & G == g2),
include.equals = FALSE)
# Initialize
variab = numeric(nrow(pairs))
pairs <- expand.grid.unique(which(W == w1 & G == g1),
which(W == w2 & G == g2),
include.equals = FALSE)
# Initialize
variab = numeric(nrow(pairs))

Copilot uses AI. Check for mistakes.
@fbargaglistoffi fbargaglistoffi merged commit 3529968 into fbargaglistoffi:master Mar 8, 2026
8 of 9 checks passed
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.

3 participants