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

Can you add some macro like @rget and @rput in RCall.jl #539

Closed
yanglipmed opened this issue Aug 26, 2018 · 2 comments
Closed

Can you add some macro like @rget and @rput in RCall.jl #539

yanglipmed opened this issue Aug 26, 2018 · 2 comments

Comments

@yanglipmed
Copy link

yanglipmed commented Aug 26, 2018

Hi, there are two convenient macro in RCall.jl, @rget and @rput, by which we can transfer variables between Julia and R without worrying about how to build a new variable in R and then copy data in Julia to it.

Could you add something like them in PyCall.jl? I tried to do it, but failed, because it hard to build a new variable in Python with py"...".

py"""...""" could do it, but I have to use it in multiple lines like this:
py"""
codes
"""
For example, there is a variable a=1233456 in Julia, then use "@PyPUT a" to automatically create a variable named "a" in Python and initialize it with 12345. How to realize this macro?

Thanks

@tkf
Copy link
Member

tkf commented Aug 26, 2018

After #517 (cc @crstnbr), I guess you can just do:

main = pyimport("__main__")
main.a = 12345

@stevengj
Copy link
Member

@tkf is right, and you can currently do main[:a] = a. You also can also do

julia> py"""
       a = $a
       """

I don't see a need for a more specialized syntax here, as creating global variables in Python, outside of py""" ... """ blocks, is not commonly needed to call Python code.

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

No branches or pull requests

3 participants