Unable to execute user defined function using pyper

266 Views Asked by At

I am trying to read data through python in my web app and then analyze it in R. For this I am using pyper to perform the analysis. While creating a function, I get the output only if I write a single statement in function definition. But if I write more than one statement, neither do I get any error nor does my code run. i.e

>>>from pyper import *  
   r('replace<-function(stmt){stmt<-gsub("@(.*?) +","||T|| ",stmt)}')

works well enough but

>>>r('replace<-function(stmt)  
    {stmt<-gsub("@(.*?) +","||T|| ",stmt)  
     stmt<-gsub("(http://t.co/)[0-9a-zA-Z]*","||U|| ",stmt)}')

does not execute. This is the same case with all other functions. I am not able to club all commands within a single block. Please suggest a solution

1

There are 1 best solutions below

0
On

May be you should call like this:

R("""replace<-function(stmt)  
    {stmt<-gsub("@(.*?) +","||T|| ",stmt)  
     stmt<-gsub("(http://t.co/)[0-9a-zA-Z]*","||U|| ",stmt)}""")