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

Calling R functions with keyword argumets that have attributes #71

Closed
mbeltagy opened this issue Oct 1, 2015 · 9 comments
Closed

Calling R functions with keyword argumets that have attributes #71

mbeltagy opened this issue Oct 1, 2015 · 9 comments

Comments

@mbeltagy
Copy link

mbeltagy commented Oct 1, 2015

If I was to call R's stars function. It is easy to invoke it with

rprint(rcall(:stars,myDf))

However if I try to set the draw.segments=TRUE as I would in R. The following invocation fails

rprint(rcall(:stars,myDf,draw.segments=true))
ERROR: syntax: keyword argument is not a symbol: "draw.segments"

I saw nothing in the documentation to clarify how this might be handled.

@dmbates
Copy link
Member

dmbates commented Oct 1, 2015

I don't think the example is reproducible so I will ask you to try

rprint(rcall(:stars,myDF;draw.segments=true))

to see if that works. In Julia named arguments are allowed only after the ; separator.

@simonbyrne
Copy link
Member

actually the separator is only required for definitions, you don't need it for calling

@mbeltagy
Copy link
Author

mbeltagy commented Oct 1, 2015

I tried it and it did not work. I got the same error

rprint(rcall(:stars,myDf;draw.segments=true))
ERROR: syntax: keyword argument is not a symbol: "draw.segments"

The trouble appears to be with draw.segments. Julia seems to be having trouble passing it along to R. In Julia, I have never come across keyword arguments with attributes as in R.

@simonbyrne
Copy link
Member

@mbeltagy I don't yet have a good way to handle that case.

@randy3k
Copy link
Member

randy3k commented Oct 1, 2015

It is one of the ways to mimic this, certainly not a good way.

eval(:(rcall(:stars,:mtcars,$(symbol("draw.symbol"))=true)))

It may be also of interest to implement a @rcall macro to handle non-standard keywords and lazy evaluation #42.

@mbeltagy
Copy link
Author

mbeltagy commented Oct 1, 2015

It works!

 eval(:(rcall(:stars,:mtcars,$(symbol("draw.segments"))=true)))

The syntax is a bit cumbersome though. I look forward to an @rcall macro.

@simonbyrne
Copy link
Member

A neat hack I once came across somewhere (I don't remember where). Define the following:

macro var_str(s)
    symbol(s)
end

then the following should work:

rprint(rcall(:stars,myDF;var"draw.segments"=true))

@simonbyrne
Copy link
Member

I would be okay with incorporating something along these lines. Any suggestions for a good prefix? r, s, and v are all taken by various uses in Base (which, unfortunately, are the 3 most relevant in this case).

@simonbyrne
Copy link
Member

I've added the above macro, so hopefully that is a reasonable solution.

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

4 participants