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

Make it easy to convert R variables to Sage #12010

Open
kcrisman opened this issue Nov 11, 2011 · 4 comments
Open

Make it easy to convert R variables to Sage #12010

kcrisman opened this issue Nov 11, 2011 · 4 comments

Comments

@kcrisman
Copy link
Member

This was initially requested at this ask.sagemath.org question.

Question:

If I have a bunch of notebook cells with R code using the %r method, 
is there an easy way to grab the data as a varible in Python/Sage 
without converting the whole thing to use r.command syntax?

My answer, which I think should now be wrapped somehow given that it got three upvotes (a lot for ask.sagemath):

Victory! I knew this should be possible.
In the notebook:
%r
a <- c(1,2,3)
a

[1] 1 2 3

from sage.interfaces.r import RElement
b = RElement(r,'a')
c = b._sage_()
c

[1, 2, 3]
and then you can do stuff to c because it's not an RElement.
c[1] = 3
c

[1, 3, 3]
I don't know whether this is worth wrapping slightly better, 
or if that is even possible. But hopefully this works for you!

Note that this will only work for things with a nice conversion - but better than the current situation.

Component: packages: standard

Keywords: R, r-project

Issue created by migration from https://trac.sagemath.org/ticket/12010

@kcrisman

This comment has been minimized.

@mwhansen
Copy link
Contributor

comment:2

You can just do r('a')._sage_().

@kcrisman
Copy link
Member Author

comment:3

Hmm, nice work; you always know how to make it easy!

So maybe this ticket should be about adding this type of example to the r? documentation, because I don't think there is much about using it in the notebook right now, but I bet a lot of people would like to know this.

Unless you can think of an even shorter or underscore-less syntax that would make sense for this...

@kcrisman
Copy link
Member Author

Changed keywords from none to R, r-project

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@mkoeppe mkoeppe removed this from the sage-6.4 milestone Dec 29, 2022
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

4 participants