Re: [Rpy] How can create a R function which have two or more parameters?
Hi everyone, I want to create a R function which can be used as a parameter in the function "outer", I tried the rternalize way which expose python function to R. However, it doesn't work, the following being the problems which I encountered. import rpy2.rinterface as ri seq = ri.globalenv.get("seq") outer = ri.globalenv.get("outer") #a1, a2, b1, b2 are a list which have only a element a = seq(ri.IntSexpVector(a1),ri.IntSexpVector(a2),length=ri.IntSexpVector([50,])) b = seq(ri.IntSexpVector(b1),ri.IntSexpVector(b2),length=ri.IntSexpVector([50,])) #create a python function with lambda and expose it to R funcp = lambda x, y: x+y funcp_f = ri.rternalize(funcp) z = outer(a, b , funcp_f) gives a Error in FUN(X, Y, ...): unsupported oper and type(s) for +: 'rpy2.rinterface.SexpVector' and 'rpy2.rinterface.SexpVector' The only example I can find of creating R function that I can find is creating a function having only one parameter, like this example: from rpy2.robjects.vectors import FloatVector from rpy2.robjects.packages import importr import rpy2.rinterface as ri stats = importr('stats') # Rosenbrock Banana function as a cost function # (as in the R man page for optim()) def cost_f(x): x1 = x[0] x2 = x[1] return 100 * (x2 - x1 * x1)**2 + (1 - x1)**2 # wrap the function f so it can be exposed to R cost_fr = ri.rternalize(cost_f) # starting parameters start_params = FloatVector((-1.2, 1)) # call R's optim() with our cost funtion res = stats.optim(start_params, cost_fr) So how can I get a function can be used in "outer"? Any words would be welcome. Thanks! Fangyu He -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/___ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list
[Rpy] How can create a R function which have two or more parameters?
??: Re: [Rpy] How can create a R function which have two or more parameters? ??: Wed, 29 Feb 2012 08:31:49 +0800 ???:Fangyu He ???: RPy help, support and design discussion list Hi everyone, I want to create a R function which can be used as a parameter in the function "outer", I tried the rternalize way which expose python function to R. However, it doesn't work, the following being the problems which I encountered. import rpy2.rinterface as ri seq = ri.globalenv.get("seq") outer = ri.globalenv.get("outer") #a1, a2, b1, b2 are a list which have only a element a = seq(ri.IntSexpVector(a1),ri.IntSexpVector(a2),length=ri.IntSexpVector([50,])) b = seq(ri.IntSexpVector(b1),ri.IntSexpVector(b2),length=ri.IntSexpVector([50,])) #create a python function with lambda and expose it to R funcp = lambda x, y: x+y funcp_f = ri.rternalize(funcp) z = outer(a, b , funcp_f) gives a Error in FUN(X, Y, ...): unsupported oper and type(s) for +: 'rpy2.rinterface.SexpVector' and 'rpy2.rinterface.SexpVector' The only example I can find of creating R function that I can find is creating a function having only one parameter, like this example: from rpy2.robjects.vectors import FloatVector from rpy2.robjects.packages import importr import rpy2.rinterface as ri stats = importr('stats') # Rosenbrock Banana function as a cost function # (as in the R man page for optim()) def cost_f(x): x1 = x[0] x2 = x[1] return 100 * (x2 - x1 * x1)**2 + (1 - x1)**2 # wrap the function f so it can be exposed to R cost_fr = ri.rternalize(cost_f) # starting parameters start_params = FloatVector((-1.2, 1)) # call R's optim() with our cost funtion res = stats.optim(start_params, cost_fr) So how can I get a function can be used in "outer"? Any words would be welcome. Thanks! Fangyu He -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/___ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list
[Rpy] How can create a R function which have two or more parameters?
Hi everyone, I want to create a R function which can be used as a parameter in the function "outer", I tried the rternalize way which expose python function to R. However, it doesn't work, the following being the problems which I encountered. import rpy2.rinterface as ri seq = ri.globalenv.get("seq") outer = ri.globalenv.get("outer") #a1, a2, b1, b2 are a list which have only a element a = seq(ri.IntSexpVector(a1),ri.IntSexpVector(a2),length=ri.IntSexpVector([50,])) b = seq(ri.IntSexpVector(b1),ri.IntSexpVector(b2),length=ri.IntSexpVector([50,])) #create a python function with lambda and expose it to R funcp = lambda x, y: x+y funcp_f = ri.rternalize(funcp) z = outer(a, b , funcp_f) gives a Error in FUN(X, Y, ...): unsupported oper and type(s) for +: 'rpy2.rinterface.SexpVector' and 'rpy2.rinterface.SexpVector' The only example I can find of creating R function that I can find is creating a function having only one parameter, like this example: from rpy2.robjects.vectors import FloatVector from rpy2.robjects.packages import importr import rpy2.rinterface as ri stats = importr('stats') # Rosenbrock Banana function as a cost function # (as in the R man page for optim()) def cost_f(x): x1 = x[0] x2 = x[1] return 100 * (x2 - x1 * x1)**2 + (1 - x1)**2 # wrap the function f so it can be exposed to R cost_fr = ri.rternalize(cost_f) # starting parameters start_params = FloatVector((-1.2, 1)) # call R's optim() with our cost funtion res = stats.optim(start_params, cost_fr) So how can I get a function can be used in "outer"? Any words would be welcome. Thanks! Fangyu He -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/___ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list
[Rpy] R function written with python can't work as parameter in R
Hi everyone, I want to create a R function which can be used as a parameter in the function "outer", I tried the rternalize way which expose python function to R. However, it doesn't work, the following being the problems which I encountered. import rpy2.rinterface as ri seq = ri.globalenv.get("seq") outer = ri.globalenv.get("outer") #a1, a2, b1, b2 are a list which have only a element a = seq(ri.IntSexpVector(a1),ri.IntSexpVector(a2),length=ri.IntSexpVector([50,])) b = seq(ri.IntSexpVector(b1),ri.IntSexpVector(b2),length=ri.IntSexpVector([50,])) #create a python function with lambda and expose it to R funcp = lambda x, y: x+y funcp_f = ri.rternalize(funcp) z = outer(a, b , funcp_f) gives a Error in FUN(X, Y, ...): unsupported oper and type(s) for +: 'rpy2.rinterface.SexpVector' and 'rpy2.rinterface.SexpVector' The only example I can find of creating R function that I can find is creating a function having only one parameter, like this example: from rpy2.robjects.vectors import FloatVector from rpy2.robjects.packages import importr import rpy2.rinterface as ri stats = importr('stats') # Rosenbrock Banana function as a cost function # (as in the R man page for optim()) def cost_f(x): x1 = x[0] x2 = x[1] return 100 * (x2 - x1 * x1)**2 + (1 - x1)**2 # wrap the function f so it can be exposed to R cost_fr = ri.rternalize(cost_f) # starting parameters start_params = FloatVector((-1.2, 1)) # call R's optim() with our cost funtion res = stats.optim(start_params, cost_fr) So how can I get a function can be used in "outer"? Any words would be welcome. Thanks! Fangyu He -- Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/___ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list
Re: [Rpy] Problem with installing rpy2 to Python3
Dear Yuanda Zhu I did never do install rpy2 to Python3, but I got it for Python2.7 easily with the help of apt-get before. I think that you may try it if your os is ubuntu or its likes. I hope it does work, which doesn't take much time. The following is the code used in terminal. sudo apt-get update sudo apt-get install r-base r-base-dev sudo apt-get install python-rpy2 Fangyu He ? 03/25/2012 03:47 PM, Yuanda Zhu ??: Hi, When I was trying to install rpy2-2.2.5 to Python-3.2.2 in Win7, the error msg said "Tried to guess R's HOME but no R command in the PATH." I am new to programming, so wish you could provide some help. Many thanks, Y.Z. -- This SF email is sponsosred by: Try Windows Azure free for 90 days Click Here http://p.sf.net/sfu/sfd2d-msazure ___ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list -- This SF email is sponsosred by: Try Windows Azure free for 90 days Click Here http://p.sf.net/sfu/sfd2d-msazure___ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list
Re: [Rpy] Custom R functions from Python
rpy2 is more convenient. All you need is just read the following page. The documentation is comprehensive. http://rpy.sourceforge.net/rpy2/doc-2.1/html/index.html 2013/3/15 Rahul Manghwani > Hi, > > I am a newbie to R, Is it possible to call custom R functions from python > using rpy ? > > -- > Regards, > Rahul > > > -- > Everyone hates slow websites. So do we. > Make your web apps faster with AppDynamics > Download AppDynamics Lite for free today: > http://p.sf.net/sfu/appdyn_d2d_mar > ___ > rpy-list mailing list > rpy-list@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/rpy-list > > -- Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://p.sf.net/sfu/appdyn_d2d_mar___ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list