tidyverse / magrittr

Improve the readability of R code with the pipe
https://magrittr.tidyverse.org
Other
959 stars 157 forks source link

Bug: Rstudio completion with "mrgmod" S4 class object #253

Closed FelicienLL closed 1 year ago

FelicienLL commented 2 years ago

Hello, First thank you for these awesome packages. Just reporting a minor issue: Rstudio completion does not work on "mrgmod" S4 class objects when used inside a %>% pipe. However, because it works with the base |> pipe, so I assume the problem is related to magrittr, but maybe I'm wrong.

library(mrgsolve)
mod <- modlib("irm1")
mod |> mrgsim(
# +tab: completion works
mod %>% mrgsim(
# +tab: completion returns error messages and stops

These are quite special S4 objects, since they have names() and a $ extraction method.

I tried to debug Rstudio completion method with debug(search_envs()[["tools:rstudio"]]$.rs.getRChainCompletions). Just noticed that:

Was this difference between |> and %>% expected at this point? Is it only related to the non-standard construction of these "mrgmod" objects, or could something be fixed on your side? Or do you think it is more related to Rstudio?

Many thanks in advance

Félicien

lionel- commented 2 years ago

This is more of an RStudio issue I think.

SimonDedman commented 2 years ago

HI, I'm not sure if this related (this is all at the edge of my mental pay grade!) but recently magrittr assignment pipe (%<>%) doesn't work - instead of assigning the chain of operations to the LHS object, it instead returns the result in the console.

However, I have also recently started using the base R pipe (|>) instead of the magrittr pipe (%>%).

When I replace base pipes with magrittr pipes, the assignment pipe works as expected. Is this something that can/should be fixed at your (magrittr team) end, or something for the base R folks? Thanks!

lionel- commented 2 years ago

The |> rewrites the input in nested form at parse time:

quote(a %<>% b() |> c())
#> c(a %<>% b())

So there is no appealing way to make it work in a %<>% pipeline.

FelicienLL commented 1 year ago

Will be fixed in the next version of rstudio. Thanks for your comment. https://github.com/rstudio/rstudio/issues/10538