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 > rpy-list@lists.sourceforge.net > 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 rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list