rpy2

NA_character_ not identidied as NaN after importing it into Python with rpy2

NA_character_ not identidied as NaN after importing it into Python with rpy2 Question: I am using the following code inside a R magic cell: %%R -o df library(tibble) df <- tibble(x = c("a", "b", NA)) However, when I run in another cell (a Python one): df.isna() I get x 1 False 2 False 3 False …

Total answers: 1

NotImplementedError: Conversion 'rpy2py' not defined for objects of type '<class 'rpy2.rinterface.SexpClosure'>' only after I run the code twice

NotImplementedError: Conversion 'rpy2py' not defined for objects of type '<class 'rpy2.rinterface.SexpClosure'>' only after I run the code twice Question: If I run the following code once it works. import numpy as np import rpy2.robjects as robjects x = np.linspace(0, 1, num = 11, endpoint=True) y = np.array([-1,1,1, -1,1,0, .5,.5,.4, .5, -1]) r_x = robjects.FloatVector(x) r_y …

Total answers: 2

R kernel crashes while loading R package using rpy2

R kernel crashes while loading R package using rpy2 Question: First of all, I’m new to rpy2 / jupyter so please don’t judge me if this isn’t the correct place to ask my question. I am trying to set up an integrated workflow for data analysis using R and Python and I encounter the following …

Total answers: 4

How to pass a date to R from Python using rpy2

How to pass a date to R from Python using rpy2 Question: I want to call a function from R which requires a Date object. I’m struggling to call this function using Rpy2. Here’s an example: An R function that takes a date d <- as.Date("2009-08-17") format(d, "%d/%m/%Y") [1] "17/08/2009" Now I want to call …

Total answers: 1

Add column to DataFrame in rpy2

Add column to DataFrame in rpy2 Question: I’m using R in python with rpy2. I have a dataframe with some columns in it and I want to add additional one. As far as I understand I, in R I would write something like this: df$new_colname <- cumsum(df$oldcolname) But how can I translate this to rpy2? …

Total answers: 2

RPy2 importing R source function generates error

RPy2 importing R source function generates error Question: As the title says, I have a Python script that uses Rpy2 and imports an R file. R file contents (named r_code.R): test_function <- function(A) { A <- as.vector(A) return(list(SUM=sum(A))) } Python file contents (named rpy2_test.py): import numpy as np import rpy2.robjects as robjects import rpy2.robjects.numpy2ri rpy2.robjects.numpy2ri.activate() …

Total answers: 2

Calling R script from python using rpy2

Calling R script from python using rpy2 Question: I’m very new to rpy2, as well as R. I basically have a R script, script.R, which contains functions, such as rfunc(folder). It is located in the same directory as my python script. I want to call it from Python, and then launch one of its functions. …

Total answers: 1

rpy2: Convert FloatVector or Matrix back to a Python array or list?

rpy2: Convert FloatVector or Matrix back to a Python array or list? Question: I’m using rpy2 and I have this issue that’s bugging me: I know how to convert a Python array or list to a FloatVector that R (thanks to rpy2) can handle within Python. Can the opposite can be done? For example, I …

Total answers: 4