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

R custom string literal #48

Closed
simonbyrne opened this issue Apr 15, 2015 · 4 comments
Closed

R custom string literal #48

simonbyrne opened this issue Apr 15, 2015 · 4 comments

Comments

@simonbyrne
Copy link
Member

It might be nice to be able to call R code via a macro string literal, similar to this proposal: JuliaInterop/MATLAB.jl#29.

Of course, one problem would be that using $ for variable substitution would conflict with R lookup usage.

@randy3k
Copy link
Member

randy3k commented Apr 16, 2015

I believe there is no problem of using $. With this macro,

macro s_mstr(x)
    quote
        rprint($x)
    end
end

there is no problem in extracting the list element by using $:

julia> s"""
       x = list(a=1,b=2)
       y = x$a
       """
[1] 1

PS: unfortunately, r_mstr is used, so we have to think of something different. I vote for s_mstr.

@simonbyrne
Copy link
Member Author

Sorry, what I meant was that it might be difficult to use $ the same way the proposed mat_str macro does, i.e. for copying the corresponding julia variable to R.

@simonster
Copy link
Member

You could allow only $ followed by parens, e.g. $(a), unless that's actually valid R syntax in some context. I believe you could backslash-escape other cases of $ before passing to the parser. Alternatively, it may be that valid uses of $ for interpolation are never valid R syntax, so there would be no ambiguity. (I don't know R well enough to say if this is the case.)

The hardest part in JuliaInterop/MATLAB.jl#29 was determining whether a variable/expression is assigned or used. This is easier for MATLAB than other languages because the MATLAB parser sucks and can't itself handle cases that would be hard for us to handle, but it still turned out to be non-trivial. However, if you can actually get the AST from R, this might not be too hard.

@randy3k
Copy link
Member

randy3k commented Mar 20, 2016

This can also be closed by #94.

@randy3k randy3k closed this as completed Mar 20, 2016
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