-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Diagnostics: No symbol in scope when assigning variables in function calls #3048
Comments
This is valid code that we currently do not correctly lint: sum(x <- 1:10)
#> [1] 55
x * 2
#> [1] 2 4 6 8 10 12 14 16 18 20 Created on 2024-05-07 with reprex v2.1.0 It says "no symbol named 'x' in scope" for the second |
In theory, we should analyse the semantics of argument evaluation and only consider Such a pragmatic approach will have lots of false positives though, in particular For the longer term, the annotations discussed last year at the R sprint would be useful here: https://bugs.r-project.org/show_bug.cgi?id=14354 |
I just came across a variant of this in cli, except it's a variable assignment in an The general form that's problematic: if (nzchar(ASDF <- Sys.getenv("ASDF"))) {
if (ASDF == "whatever") {
message("hi")
}
} In Positron, the The real world example: https://github.com/r-lib/cli/blob/7ca06ff9c1c881359b562ecb98a1414e44d78fb8/R/ansi-hyperlink.R#L347-L355 |
I'm now thinking we should be overly optimistic about potential assignments instead of overly cautious. |
## Positron Notes ### Release Notes #### New Features - The variable pane now supports labels from the {haven} package (#5327. - The variable pane has improved support for formulas (#4119). #### Bug Fixes - Assignments in function calls (e.g. `list(x <- 1)`) are now detected by the missing symbol linter to avoid annoying false positive diagnostics (#3048). The downside is that this causes false negatives when the assignment happens in a call with local scope, e.g. in `local()` or `test_that()`. In these cases the nested assignments will incorrectly overlast the end of the call. We prefer to be overly permissive than overly cautious in these matters. - The following environment variables are now set in the same way that R does: - `R_SHARE_DIR` - `R_INCLUDE_DIR` - `R_DOC_DIR` This solves a number of problems in situations that depend on these variables being defined (#3637).
### Release Notes #### New Features - The variable pane now supports labels from the {haven} package (#5327. - The variable pane has improved support for formulas (#4119). #### Bug Fixes - Assignments in function calls (e.g. `list(x <- 1)`) are now detected by the missing symbol linter to avoid annoying false positive diagnostics (#3048). The downside is that this causes false negatives when the assignment happens in a call with local scope, e.g. in `local()` or `test_that()`. In these cases the nested assignments will incorrectly overlast the end of the call. We prefer to be overly permissive than overly cautious in these matters. - The following environment variables are now set in the same way that R does: - `R_SHARE_DIR` - `R_INCLUDE_DIR` - `R_DOC_DIR` This solves a number of problems in situations that depend on these variables being defined (#3637). <!-- Thank you for submitting a pull request. If this is your first pull request you can find information about contributing here: * https://github.com/posit-dev/positron/blob/main/CONTRIBUTING.md We recommend synchronizing your branch with the latest changes in the main branch by either pulling or rebasing. --> <!-- Describe briefly what problem this pull request resolves, or what new feature it introduces. Include screenshots of any new or altered UI. Link to any GitHub issues but avoid "magic" keywords that will automatically close the issue. If there are any details about your approach that are unintuitive or you want to draw attention to, please describe them here. -->
Verified Fixed
Test scenario(s)Verified with Julia's example Link(s) to TestRail test cases run or created: |
Discussed in https://github.com/posit-dev/positron-beta/discussions/175
Originally posted by jeffkeller-einc May 7, 2024
I don't know what this pattern is called, but I do it a lot to modularize my non-package R projects.
The text was updated successfully, but these errors were encountered: