Opened 10 years ago
Last modified 7 years ago
#12010 new enhancement
Make it easy to convert R variables to Sage
Reported by: | kcrisman | Owned by: | tbd |
---|---|---|---|
Priority: | minor | Milestone: | sage-6.4 |
Component: | packages: standard | Keywords: | R, r-project |
Cc: | Merged in: | ||
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
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.
Change History (8)
comment:1 Changed 10 years ago by
- Description modified (diff)
comment:2 Changed 10 years ago by
comment:3 Changed 10 years ago by
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...
comment:4 Changed 10 years ago by
- Keywords R r-project added
comment:5 Changed 8 years ago by
- Milestone changed from sage-5.11 to sage-5.12
comment:6 Changed 8 years ago by
- Milestone changed from sage-6.1 to sage-6.2
comment:7 Changed 8 years ago by
- Milestone changed from sage-6.2 to sage-6.3
comment:8 Changed 7 years ago by
- Milestone changed from sage-6.3 to sage-6.4
You can just do
r('a')._sage_()
.