[R] Multi-line input to rsympy

Gabor Grothendieck ggrothendieck at gmail.com
Sat Mar 5 21:10:02 CET 2011


On Fri, Mar 4, 2011 at 6:48 AM, Joanna Lewis <joanna.lewis at ucl.ac.uk> wrote:
> Dear R users,
>
> I have been using rsympy to solve a set of simultaneous equations from R.
> There are two solutions for the variable I'm interested in, xx[0] and xx[1],
> which are in terms of symbols called lam and conc. I'd like to pick out the
> one which is positive at (lam=0, conc=0) and call it mysol.
>
> In python I could write:
>
> if (xx[0].subs(lam,0)).subs(conc,0)>0:
>  mysol=xx[0]
> else:
>  mysol=xx[1]
>
> but I'm not sure how to do it from R via rsympy. The various combinations of
> \t and \n characters and spaces I've tried haven't worked, and I haven't
> been able to find any examples online or in the help file.
>
> Do you know whether it is possible to enter multi-line input using rsympy,
> and if so how?
>

You can run multi-line python commands in Jython:

> .Jython$exec("x = 1")
> .Jython$exec("if x == 1:
+    z = 2
+ else:
+    z = 3")
> z <- .Jython$get("z")
> .jstrVal(z)
[1] "2"


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list