-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Thanks for the fast answer, Laurent!
The anonymous function solution is OK, when one needs to work
occasionally with some piece of code. Unfortunately - my problem is a
little bit different:
I will be given a whole library of custom R functions, I need to access
them with Python, provide some arguments and gather some results. All R
code is maintained by my colleague who is R master and there's no option
he will code R in Python, it's my task to provide R-to-Python
interface, which is a part of a bigger system, which written purely in
Python.
Any other suggestion are greatly welcome!
I'm a R newbie (it's my first hours with this language, though), I guess
one can provide a package (library) of functions and register them in R
namespace - the question is: if I provide such a mechanism with rpy2
(using the R "library" function) will all the functions became visible
for rpy2?
I'm going to check this in a minute...
Laurent Gautier pisze:
> Sebastian Żurek wrote:
>> Hi!
>>
>> I want to use rpy2 in my Python software to make a use of some custom
>> R-scripts/functions.
>>
>> Is it possible, to call a custom R function with rpy2?
>> For example, having the custom (taken from R tutorial) definition:
>>
>> twosam <- function(y1, y2) {
>> n1 <- length(y1); n2 <- length(y2)
>> yb1 <- mean(y1); yb2 <- mean(y2)
>> s1 <- var(y1); s2 <- var(y2)
>> s <- ((n1-1)*s1 + (n2-1)*s2)/(n1+n2-2)
>> tst <- (yb1 - yb2)/sqrt(s*(1/n1 + 1/n2))
>> tst
>> }
>>
>> how to call it with rpy2? I guess, there should be a R-packaged that
>> contains it implemented and loaded?
>>
>> In python code, I want to use something like:
>>
>> twosam = robjects.r['twosam']
>
> If you only want to access your function from Python, having making it
> an anonymous R function might one way to go.
>
> twosam = robjects.r('''
> function(y1, y2) {
> n1 <- length(y1); n2 <- length(y2)
> yb1 <- mean(y1); yb2 <- mean(y2)
> s1 <- var(y1); s2 <- var(y2)
> s <- ((n1-1)*s1 + (n2-1)*s2)/(n1+n2-2)
> tst <- (yb1 - yb2)/sqrt(s*(1/n1 + 1/n2))
> tst
> }
> ''')
>
>
>
> twosam(robjects.IntVector(range(10)),
> robjects.IntVector(range(10)))
>
>
>
> L.
>
>
>> Thanks for *any* clues!
>> Sebastian
>>
>> ------------------------------------------------------------------------------
>> Are you an open source citizen? Join us for the Open Source Bridge
>> conference!
>> Portland, OR, June 17-19. Two days of sessions, one day of unconference:
>> $250.
>> Need another reason to go? 24-hour hacker lounge. Register today!
>> http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org
>> _______________________________________________
>> rpy-list mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/rpy-list
>
>
> ------------------------------------------------------------------------------
> Are you an open source citizen? Join us for the Open Source Bridge conference!
> Portland, OR, June 17-19. Two days of sessions, one day of unconference: $250.
> Need another reason to go? 24-hour hacker lounge. Register today!
> http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org
> _______________________________________________
> rpy-list mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/rpy-list
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkpBHXEACgkQGAS1N8/5iJ54YQCfTdmCeOtaLdyM81YN3I5r+qrB
XzwAn1TTB7vVOymt2imTbq0bY9APsTEa
=Mrnm
-----END PGP SIGNATURE-----
------------------------------------------------------------------------------
_______________________________________________
rpy-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rpy-list