REditorSupport / REditorSupport/languageserver

Incorrect `variable assigned but may not be used` warning

Open
#671 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
675
Forks
118
Avg merge
1d 37m
Merged PRs (30d)
11

Description

With the following minimal-ish code snippet, I'm getting a warning that model was assigned but may not be used:

boot_wls <- function(data, indices) {
  data <- data[indices, ]
  model <- lm(y ~ x1 + x2 + x3, data)
  w <- 1 / fitted(lm(abs(residuals(model)) ~ x1 + x2 + x3, data))^2
  w
}

Contributor guide

No contributing guide indexed for this repository

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.

Research direction

Start by reproducing the warning with the R function shown in the issue and trace the language server's unused-variable analysis for the model assignment. Determine why its use through residuals(model) is missed; done means this example no longer reports model as possibly unused, with regression coverage for the case.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.