Closed noirot closed 1 year ago
Are you sure you are sourcing the correct R file? The one at the top is called 'test.R', but you are sourcing 'tmp.R'.
The other thing you can try is to replace the last line with:
conn.r.r_test(conn.ref.iris, 'Species')
By using conn.ref
instead of conn.r
the value of iris
will be directly taken from the R namespace without transferring it first to Python and then back to R.
Perfect it work's well ! Thanks you.
Thanks a lot for the conn.ref, it works on this example ! Actually, this example was not what I was doing, it was more to understand. My problem occurs with R functions returning a data.frame. To reproduce, I have the test.R file, with the function r_test returning a data.frame, as test.R
r_test <- function() { df <- data.frame (first_column = c("value_1 ", "value_2"), second_column = c("value_1", "value_2") ) return (df) }
an the main python file loading the file in the R session and assigning the result in a variable named test as following :
import pyRserve conn = pyRserve.connect() conn.ref.source("test.R") conn.ref.assign('test', conn.ref.r_test())
when accessing from R the variable test is no longer a data.frame but a list, thus : conn.eval('test[, "second_column"]')
returns the error : pyRserve.rexceptions.REvalError: Error in test[, "second_column"] : number of dimensions incorrect
The conn.ref solution doesn't seem to work, any idea ? thanks for your help
Hmm, I haven't worked in that area for a while ... seems like the 'assign()' method still transfers the result of r_test()
to Python first, and then retransfers it to R. During that transfer the proper data type seems to get lost. This could indeed be a bug in pyRserve, however currently and in the near future I will not have time to track that down, i'm sorry. But feel free to dig into the code and help fixing it, if you want to.
Closed.
I'm new in pyRserve and Rserve, and I have a problem with data.frame representation. I do have a function that read a data.frame object and print 1 variable content, given by :
and a main function in python, that uses the previous function on the iris data.frame :
This return an error :