I have been attempting to familiarize myself with the new Python interface in JMP 18. One of the questions I am exploring is: "Is it possible to write a Python program in the JMP environment that executes r modules. The very simple program I am using is
# Import the necessary libraries
import numpy as np
from rpy2.robjects.packages import importr
import rpy2.robjects as ro
# Create a numpy array
data = np.array([1, 2, 3, 4, 5])
# Convert the numpy array to an R vector
r_vector = ro.FloatVector(data)
# Import the base package in R
base = importr('base')
# Calculate the mean of the vector in R
mean = base.mean(r_vector)
# Convert the mean back to a Python float
mean_py = np.array(mean)[0]
print(f"The mean of the data is {mean_py}")
I installed the rpy2 package using the JSL
Python Install Packages( "rpy2");
It installed without issue. I also installed it in my native 3.8 version of Python and in the native version of Python 3.11
The Python code runs without error in Python 3.8 and in JMP's installed 3.11.
However, when executing the code in Python under JMP 18, as soon as line 3 is run, JMP immediately goes away.
from rpy2.robjects.packages import importr
Does anyone have any ideas as to why this is happening?