RCall.jl
RCall.jl copied to clipboard
Support assignment to splatted variables in REPL R""
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.
Alternatively, we can provide some helper functions. For example
R> jput(foo)
Yes, that would also be handy!
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.
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?
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.
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}"
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.