Skip to content
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

Wrong argument suggested when pipe precedes function in R #1320

Open
ntentes opened this issue Sep 14, 2023 · 3 comments
Open

Wrong argument suggested when pipe precedes function in R #1320

ntentes opened this issue Sep 14, 2023 · 3 comments
Labels
area: kernels Issues related to Jupyter kernels and LSP servers bug Something isn't working lang: r

Comments

@ntentes
Copy link

ntentes commented Sep 14, 2023

Positron Version:

Positron Version: 2023.09.0 (Universal) build 143
Code - OSS Version: 1.79.0
Commit: 8277b72
Date: 2023-09-14T02:38:05.517Z
Electron: 22.3.10
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Darwin arm64 22.6.0

Steps to reproduce the issue:

Coding in R and using a pipe (either %>% or |>) results in auto-suggestions suggesting the first argument of the function. Almost always, the first argument does not need to be specified since it's piped into the function (screenshot 1 -- I'm entering name but the board argument is highlighted).

image

I looked back to RStudio's behaviour and there's no argument highlighting so it's not as in your face, which is probably why I haven't noticed this before (2).

image

I don't explicitly name arguments in data transformation scripts, especially when using dplyr. When you do specify the argument it highlights the correct argument (3).

image

In certain situations, I don't think you can specify the correct argument even if you wanted to (4 -- most dplyr situations).

image

What did you expect to happen?

Suggestions recognizing there is a preceding pipe and highlighting the most likely argument (usually the second argument of the function).

Were there any error messages in the output or Developer Tools console?

No.

@jthomasmock
Copy link
Contributor

For what it's worth - we're currently chasing down a set of tricky issues in RStudio with pipes, as a result of some of the first vs second argument being hidden, shown, etc: rstudio/rstudio#13613
Users seem to be surprised by the behavior in both directions (first vs second argument preference).

Also, both the magrittr pipe and the base R pipe allow for piping to arguments beyond the first as well.

library(magrittr)

multi_fn <- function(multiplier, vector){
    vector * multiplier
}

c(1,2,3) |> multi_fn(multiplier = 2, vector = _)
#> [1] 2 4 6

c(1,2,3) %>% multi_fn(multiplier = 3, vector = .)
#> [1] 3 6 9

Created on 2023-09-14 by the reprex package (v2.0.1)

@kevinushey
Copy link
Contributor

In theory, because the R kernel has a proper AST it can examine, we could handle each of these cases -- this is something that's much harder to do in RStudio.

@petetronic petetronic added this to the Release Candidate milestone Feb 26, 2024
@wesm wesm added lang: r bug Something isn't working labels Feb 29, 2024
@jennybc
Copy link
Member

jennybc commented Apr 15, 2024

Came up in private beta https://github.com/posit-dev/positron-beta/discussions/112

@lionel- lionel- added the area: kernels Issues related to Jupyter kernels and LSP servers label May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: kernels Issues related to Jupyter kernels and LSP servers bug Something isn't working lang: r
Projects
None yet
Development

No branches or pull requests

7 participants