Publication date: 07/15/2025

RPY2

rpy2 is a Python-to-R bridge. It works by embedding R within Python by loading the R shared libraries into Python as an extension. When run within the JMP Python integration, Python (and therefore R) are in the JMP memory space.

RPY2 is available at https://pypi.org/project/rpy2/

You can install rpy2 from JMP by using JSL’s Python Install Packages(“rpy2”), or by running this Python script from JMP:

import jmp
from jmputils import jpip
jpip('install', 'rpy2')

Even if you have rpy2 in a command line Python environment, you must install it from JMP to ensure that JMP can locate the installed package.

The code below imports the necessary packages, then performs a try/except for importing rpy2. If not found, rpy2 is installed and then another attempt is made to import and load rpy2.

import jmp
from jmputils import jpip
import os
import platform
import importlib
try:
	import rpy2
except ModuleNotFoundError as e:
	print('Module rpy2 not found, running install')
	jpip('install', 'rpy2')
	import rpy2
	importlib.reload(rpy2)
#get info about the rpy2 installed package
print(f'\nrpy2 path: {rpy2.__path__}')
print(f'\nrpy2 version: {rpy2.__version__}')

The Scripting Index contains examples of the updated JSL R functions, as well as documentation and examples of jmpex under the Python category.

For examples of directly calling rpy2 from Python, see the file R.py within the jmpex package. The jmpex package was built using direct rpy2 calls.

Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).