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

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

Closed
FelicienLL opened this issue Feb 8, 2022 · 4 comments
Closed

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

FelicienLL opened this issue Feb 8, 2022 · 4 comments

Comments

@FelicienLL
Copy link

FelicienLL commented Feb 8, 2022

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:

  • with %>%, the value chainObjectName was equal to "mod", which triggers a [[ ]] extraction of each element in names, which is the origin of the error messages. Completion aborts.
  • with base |>, chainObjectName was NULL, thus the aforementioned extraction step is skipped (if(length(chainObjectName)) statement), and the completion is provided by an other part of the code. Named elements never got evaluated and the proposed completion was accurate (i.e. returned the arguments of the mrgsim function, but it is the same for any function).

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-
Copy link
Member

lionel- commented Feb 8, 2022

This is more of an RStudio issue I think.

@SimonDedman
Copy link

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-
Copy link
Member

lionel- commented Feb 14, 2022

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
Copy link
Author

Will be fixed in the next version of rstudio. Thanks for your comment. rstudio/rstudio#10538

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants