RCall.jl icon indicating copy to clipboard operation
RCall.jl copied to clipboard

Support assignment to splatted variables in REPL R""

Open davidanthoff opened this issue 8 years ago • 7 comments

I'm actually not sure this is a good idea, so more putting this up for discussion here.

Could something like

R"$x=5"

assign the 5 to the julia variable x? And the same in the REPL.

davidanthoff avatar Jun 21 '16 17:06 davidanthoff

Alternatively, we can provide some helper functions. For example

R> jput(foo)

randy3k avatar Jun 21 '16 17:06 randy3k

Yes, that would also be handy!

davidanthoff avatar Jun 21 '16 17:06 davidanthoff

I just notice that CXX.jl uses the syntax foo := bar to assign bar to a Julia global variable foo. I think this could also be applied to our case since := is not a built-in syntax of R. It is only being used in data.table and ggvis for some specific functionalities.

The remaining question is: should the assigned variable be a RObject or a converted Julia object.

randy3k avatar Jun 22 '16 17:06 randy3k

Cool! Maybe still use $, so have the syntax be $foo := bar. That way the general rule would just be that you always use a $ to refer to julia variables, which seems simpler than a different rule for reading and writing.

I think my preference would be a converted julia object, that again seems more consistent with how things work the other way round, and probably what people want in most cases.

For the R''" macro, if called in a function, this would ideally create a local variable in the function, right?

davidanthoff avatar Jun 22 '16 17:06 davidanthoff

I guess there is a difficulty in parsing $foo := bar from a block of code (one-line command is easy). There are still some details that we have to figure out.

randy3k avatar Jun 22 '16 19:06 randy3k

the reason I didn't pursue this is that I couldn't figure out the exact behaviour, e.g.

x = 1
R"for (i in 1:10) {$x <- $x + 1}"

simonbyrne avatar Jun 22 '16 19:06 simonbyrne

I think we should restrict to top level only and the right hand side must be a valid R expression. Also, a different operator for assignment should be used to avoid confusion.

Perhaps, only at the top level of R repl mode.

randy3k avatar Jun 22 '16 19:06 randy3k