Skip to content
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

Support assignment to splatted variables in REPL R"" #127

Open
davidanthoff opened this issue Jun 21, 2016 · 7 comments
Open

Support assignment to splatted variables in REPL R"" #127

davidanthoff opened this issue Jun 21, 2016 · 7 comments

Comments

@davidanthoff
Copy link

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.

@randy3k
Copy link
Member

randy3k commented Jun 21, 2016

Alternatively, we can provide some helper functions. For example

R> jput(foo)

@davidanthoff
Copy link
Author

Yes, that would also be handy!

@randy3k
Copy link
Member

randy3k commented Jun 22, 2016

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.

@davidanthoff
Copy link
Author

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?

@randy3k
Copy link
Member

randy3k commented Jun 22, 2016

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.

@simonbyrne
Copy link
Member

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}"

@randy3k
Copy link
Member

randy3k commented Jun 22, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants