On Jul 7, 5:02 am, Andrzej Giniewicz <[email protected]> wrote:
> ah, thanks - I know about r.tab, well - most of it are R commands, the
> issue is that I didn't found those sage specific ones - it would help
> if at least list of modified commands would appear in "r?" docstrings.
> Anyway, is r.set working? I used:
>
> sage: r.ls()
> character(0)
> sage: r.set('y', r([1,2,3]))
> sage: r.ls()
> [1] "sage0" "sage1" "sage2" "sage3" "sage4"
>
Dear Andrzej,
Thanks for your interest in our R interface. We really appreciate
actual practical experience with it.
Note the following in
sage: r.set?
Definition: r.set(self, var, value)
Docstring:
Set the variable var in R to what the string value evaluates to
in
R.
INPUT:
var -- a string value -- a string
EXAMPLES:
sage: r.set('a', '2 + 3') sage: r.get('a') '[1] 5'
There should be interactive help (using ?) for most methods. Anyway,
r([1,2,3]) probably doesn't evaluate to anything in R.
sage: r.set('y','c(1,2,3)')
sage: r.ls()
[1] "y"
sage: r.get('y')
'[1] 1 2 3'
Is this what you are thinking of? Basically, one can either use
things like r.eval and r.set to do things in R, like so
sage:
r.eval('kruskal.test(list(c(18,16,14,9,7,2),c(17,15,12,11,10,1),c(13,8,6,5,4,3)))')
'\n\tKruskal-Wallis rank sum test\n\ndata: list(c(18, 16, 14, 9, 7,
2), c(17, 15, 12, 11, 10, 1), c(13, 8, 6, 5, 4, 3)) \nKruskal-
Wallis chi-squared = 2.8421, df = 2, p-value = 0.2415\n'
but unfortunately not
sage: r.kruskal_test('[[18,11,7,6,5,1],[17,16,15,10,9,8],
[14,13,12,4,3,2]]')Error: object 'sage4' not found
even though many other r.method() things do work very nicely. The
problem is that so much R stuff wants a 'c()'-style vector/list but
it's not always easy to figure out how to get the interface to accept
your input. Keywords actually often work.
So I think that no one would disagree that the R integration is not
perfect yet. You can use rpy, perhaps:
sage: from rpy2 import [tab]
rinterface robjects tests
rlike rpy_classic tests_rpy_classic
but this may not be what you are looking for either.
However, lots of stuff should work fairly well this way. We would
welcome good examples of how to use the R interface more efficiently,
especially with other subsystems of Sage. I have used R reasonably
well with the combinatorics facilities in Sage, for instance.
Thanks!
- kcrisman
> and there is no variable 'y' in R env. (using sage 4.4.2 here, was it
> fixed/added/changed later on?) - anyway, variable 'y' is inserted when
> I used:
>
> %r
> letSage <- function(variable,value) { .GlobalEnv[[variable]]<-value }
>
> def setR(var, val):
> r.letSage('"%s"'%var, r(val))
>
> and called it with:
>
> setR('y', [1,2,3])
>
> so it still isn't what I look for, thout the "r(...)" for "val" helped
> to simplify it a lot. The r('var <- val') works, but requires to
> specify val as R code, so it's not best way I think. I'm looking for
> something you can pass list as argument, and preferably without r code
> and function above. The r.set if it worked would be nice I think :)
>
> cheers,
> Andrzej.
>
> On Sun, Jul 4, 2010 at 6:15 PM, Tim Joseph Dumol <[email protected]> wrote:
>
>
>
> > On Mon, Jul 5, 2010 at 12:13 AM, Tim Joseph Dumol <[email protected]> wrote:
> >> Hi Andrezj,
>
> >> On Sun, Jul 4, 2010 at 11:54 PM, Andrzej Giniewicz <[email protected]>
> >> wrote:
> >>> Hi,
>
> >>> recently I have given short introductory talk about Sage and questions
> >>> about integration with R arisen. Results of quickly put together code
> >>> is now athttp://sagenb.org/home/pub/2232/- especially, the question
> >>> was: "I have variable named x in R environment and want to get its
> >>> value, or variable named x inside Sage environment and push its value
> >>> into R, but keep the name." - what I was able to think about is quick
> >>> hack with .GlobalEnv of R, but is there better way to do what is
> >>> presented in the notebook linked above? Is there some syntax like
> >>> r["x"]=[1,2,3] or sth? If there is, I haven't noticed it yet - would
> >>> be thankful for hints.
>
> >>> Cheers,
> >>> Andrzej.
>
> >>> --
> >>> To post to this group, send email to [email protected]
> >>> To unsubscribe from this group, send email to
> >>> [email protected]
> >>> For more options, visit this group
> >>> athttp://groups.google.com/group/sage-support
> >>> URL:http://www.sagemath.org
>
> >> This should do what you wanted:
>
> >> sage: r('x <- c(1,2,3)')
> >> [1] 1 2 3
> >> sage: r('x')
> >> [1] 1 2 3
> >> sage: sageobj(r('x')) # r('x').sage() works too
> >> [1, 2, 3]
> >> sage: r([1, 2, 3])
> >> [1] 1 2 3
>
> > Oh, and:
>
> > sage: r.set('y', r([1,2,3]))
> > sage: r('y')
> > [1] 1 2 3
>
> > Try:
>
> > sage: r.<TAB>
>
> > for more commands.
> >> ---
> >> Tim Joseph Dumol <tim (at) timdumol (dot) com>
> >>http://timdumol.com
>
> > --
> > Tim Joseph Dumol <tim (at) timdumol (dot) com>
> >http://timdumol.com
>
> > --
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group
> > athttp://groups.google.com/group/sage-support
> > URL:http://www.sagemath.org
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org