Destructuring method; like `Python`'s `**` or `JavaScript`'s `...`?
- Dominant language
- R
- Stars
- 5
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
Love your work thank you for sharing. I like this package and have been looking for a way to do object destructuring.
When developing packages for `R` I end up often writing functions that call other functions and end up having to either use the `...` operator (which can only be used once. Or to manually re-assign the object like so:
```r
someFunction1 <- function(arg1, arg2) { print(stringr::str_interp('Do something with ${arg1}, and with ${arg2}')) }
someFunction2 <- function(arg3, arg4) { print(stringr::str_interp('Do something with ${arg1}, and with ${arg2}')) }
# solution with R's ...
someHigherFunction <- function(arg5, arg6, ...) {
# do something with arg5 and 6
someFunction1(...)
}
# otherwise I start having to do this; and the more nested the functions get the harder it is to manage
someHigherFunction <- function(arg5, arg6, arg1, arg2, arg3, arg4) {
# do something with arg5 and 6
someFunction1(arg1 = arg1, arg2 = arg2)
someFunction1(arg3 = arg3, arg4 = arg4)
}
# there is a solution using do.call but it is rather annoying
someHigherFunction <- function(arg5, arg6, arg1_2 = list(arg1 = "something", arg2 = "something else")) {
# do something with arg5 and 6
# not ideal but it works
do.call(someFunction1, arg1_2)
}
```
In `JavaScript` we can use object destructuring (easy for positional arguments), python has this too with it's own `**` double star operator:
```js
function foo(a, b) {
console.log(a - b);
}
let args = [10, 7];
foo(...args);
```
There are other uses for this as well but you've already implemented this:
```js
let a, b, rest;
[a, b] = [10, 20];
console.log(a);
// expected output: 10
console.log(b);
// expected output: 20
[a, b, ...rest] = [10, 20, 30, 40, 50];
console.log(rest);
// expected output: Array [30,40,50]
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing the requested R syntax and the Python and JavaScript examples in the issue. No repository files, tests, or entry points are identified, so the desired destructuring semantics and scope need clarification before implementation. Done should include an agreed syntax that forwards named arguments through nested function calls, with tests covering the supported cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100