Piped functions not showing first argument

Hello,

I have 2022.12.0 Build 353 ("Elsbeth Geranium" Release (7d165dcf, 2022-12-03) for Windows). When I pipe any function, it does not show the first argument.

I get why it does this--it's just automatically passing to the first arg. However, I think this is pretty inflexible because I often want to specify the argument anyways or pass to an argument that is NOT the first argument.

I can't see how to go back to the good old autocomplete where it shows me all of the arguments. Please help!!!

For example, if I do the below, the autocomplete offers me just ".f" and not ".x" and ".f" :frowning:

library(tidyverse)
iris%>%
  map()

I'm still struggling with this, if anyone has any insight...

As you say, piping passes in the first argument. You can't change that. And piping doesn't go anywhere other than the first argument. Maybe just specify the function without piping, then you can give whatever argument you want.

I must be missing something, because I often pipe into arguments other than the first. I do hope this changes in the future.

There seem to be multiple issues here. One is whether autocomplete is available for the first argument when something is being piped to it. I think the answer is no. Another is whether the pipe can pass the LHS to something other than the first argument. There is also the difference in the magrittr pipe (%>%) compared to the new base R pipe operator (|>).

The magrittr pipe can use the . placeholder to pass to other arguments and the base pipe uses the _ placeholder, but with limitations. Both of these work fine:

mtcars %>% lm(mpg ~ wt + disp, data = .)

mtcars |> lm(mpg ~ wt + disp, data = _)

Importantly, the base pipe actually passes to the first unnamed argument. If the first argument is named, the LHS will be passed to the next argument. The second argument of lm() is data, so this works:

mtcars |> lm(formula = mpg ~ wt + disp)

The development version of R 4.3.0 also extends the placeholder to subsetting data frames:

mtcars |> _$mpg
and
mtcars |> _[1:2]
will work.

Just my two cents.

2 Likes

Better than my explanation.

I'm glad to hear the development version will allow expressions like _[1:2], and I guess it makes sense that the native pipe will pass to the first unnamed argument. Thank you for your reply. As you mentioned, the other issue is that the user is not provided with the opportunity to autocomplete (or even view) the first argument in a pipe. This means that people will have to look at the tool tip popup as they type the function or look at documentation. RStudio, please do address at your convenience!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.