Bug: uninformative error when hypotheses weights lose its names

Closed Beginner friendly
#110 0 comments 0 reactions 0 assignees View on GitHub

A pull request for this has already been merged.

  • #111 by @xidongdxi — merged

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
70/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
r
Domain
backend

Research direction

Reproduce with the issue's snippet, then trace where graph_calculate_power -> test_input_val -> graph_generate_weights consumes hypotheses names (the failing line indexes with hyp_names). Look for the input-validation entry points in R/ that back these functions. Done means an unnamed graph$hypotheses either survives or fails with a message naming the missing names, covered by a new test under tests/testthat/.

Written by the indexing model from the issue text.

Description

bug
What happened?

Assigning directly to graph$hypotheses (a natural way to tweak weights on an existing graph) drops the hypothesis names, because the replacement vector is unnamed. Every downstream function that relies on those names then fails with an error that gives the user no hint about the real cause:

Error in matrix_weights[i + 1, ] <- hypotheses[-del_index][hyp_names] : 
  replacement has length zero
Calls: graph_calculate_power -> test_input_val -> graph_generate_weights
Session Information

No response

Reproducible Example
library(graphicalMCP)

graph <- graph_create(
  hypotheses = c(0.5, 0.5),
  transitions = matrix(c(0, 1, 1, 0), nrow = 2)
)

# Changing the weights this way drops the names
graph$hypotheses <- c(0.6, 0.4)
names(graph$hypotheses)
#> NULL

graph_calculate_power(graph, alpha = 0.025, power_marginal = c(0.8, 0.7))
#> Error in matrix_weights[i + 1, ] <- hypotheses[-del_index][hyp_names] :
#>   replacement has length zero

# Restoring the names fixes it
names(graph$hypotheses) <- c("H1", "H2")
graph_calculate_power(graph, alpha = 0.025, power_marginal = c(0.8, 0.7))  # works

Dominant language
R
Stars
23
Forks
1
Avg merge
1h 42m
Merged PRs (30d)
3

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from openpharma/graphicalMCP

All issues in openpharma/graphicalMCP

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.