-
Notifications
You must be signed in to change notification settings - Fork 14
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
Destructuring Assignment by Name #47
Comments
Someone else recently posed this to me. I feel the feature is a powerful one and could be added. I believe the syntax will prove trickiest. I have a couple initial ideas and welcome your thoughts.
|
As much as I love I like |
The |
Not yet. Funny that I use destructive assignments in Js and Scala day and night but this is not a feature that I miss often when it comes to R. I think mostly because I'm still discovering how positional destructive assignment fits in my day to day R flow. I'll let you know if I come across good use case for destructive assignment by name. |
This would be a pretty big help for multiple return values from Shiny modules. One of the things we strongly encourage people to do is use named lists to return reactives and other return values from Shiny module server functions. In these cases, the returned list usually has little inherent meaning; it's the elements of the list that you want to turn into variables. Having destructuring assignment by name would make the coupling between caller and callee robust to reordering of the named lists returned by the modules. I haven't thought much about the syntax but semantically I'm really looking for the equivalent of e.g.
|
FWIW, this is the idiom I've been using to do this:
|
c(a=, b=) %<-% list(b = 2, a = 1) 😍 |
Allow optional renaming by providing a value? c(foo=a, b=) %<-% list(b = 2, a = 1) |
That's an interesting approach I hadn't yet considered. I was working on an idea borrowed from javascript, Right now |
In Javascript we can do:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Object_destructuring
I realize that in R, while named list resembles a hash map, it is indeed ordered.
Maybe something like this?
The text was updated successfully, but these errors were encountered: