Hi,

> 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.

I know - read docstring for r.set, but I tried to use it to follow
Tims example anyway:

sage: r.set('y', r([1,2,3]))
sage: r('y')
[1] 1 2 3

I understood from Tims sample that r.set("variable", r(value)) would
set it. Anyway, the thing I want to do is function taking variable
name and pythonic list or value and using it in R to set variable
value. Exactly stuff that is done by below code.

in R:
letSage <- function(variable,value) { .GlobalEnv[[variable]]<-value }

in Sage:
def setR(var, val):
   r.letSage('"%s"'%var, r(val))

setR('y', [1,2,3])
setR('z', [1,'"ok"',3])
instead of mostly equivalent but with R syntax of vectors
r.set('y', 'c(1,2,3)')
r.set('z', 'c(1,"ok",3)')

So the syntax r.set('var', r(val)) is meant to work? I think that way
to set variable in R environment to normal list returned by other
function would improve integration a lot, at least remove some
intermediate steps.

If we are at your sample I'm tottaly aware that '[1,2,3]' would not
work, or r('[1,2,3]') - but it is r([1,2,3]) in question that
evaluates to RElement "[1] 1 2 3" and is stored in one of temporary
sage* variables, and as sample with setR shows, can be used to pass
around python list, strings and stuff.

cheers,
Andrzej.

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to