fslaborg / RProvider

Access R packages from F#
http://fslab.org/RProvider/
Other
235 stars 69 forks source link

Reduce boilerplate when using namedParams #183

Closed zanedp closed 1 year ago

zanedp commented 7 years ago

If a function like this were added, the boilerplate necessary for using namedParams would be reduced because the need to explicitly call box when the values are of different types would be eliminated:

let (=>) (key:string) (value:'a) = (key, box value)

That changes:

namedParams [
    "x", box Xs;
    "y", box Ys;   
] |> R.plot

...to this:

namedParams [
    "x" => Xs;
    "y" => Ys;
] |> R.plot

That change lowers the learning curve by eliminating the question "What's box?", and looks like dictionary initialization in Ruby, Perl, and PHP. It's a stumbling block for new users when sometimes they do not need box, and sometimes they do, especially when the type of a parameter is changed and code that worked with previous data doesn't work with new data because they forgot to box.

Maybe, including a symbol like this is frowned upon for some reason? If => already has special meaning, maybe a different symbol could be used? (It's not in F# Symbol and Operator Reference.)

I can put this in a pull request, but I'm not sure what file is most appropriate.

tpetricek commented 7 years ago

Would it be possible to go even further and write:

R.plot [ "x" => Xs; "y" => Ys ]

I think this would be nice. The only issue is that people might use the => operator for something else, so I think if we wanted to include it, it would make sense to put it in a module, so that you have to write:

open RProvider.Operators

And only then you'd see it. If you can do a PR with that (and also adding this to docs), that would be great!

AndrewIOM commented 1 year ago

You can now use the => operator by opening RProvider.Operators in release 2.1.0, as suggested above:

open RProvider.Operators

R.plot [ "x" => Xs; "y" => Ys ]