Reputation: 1838
I simply tried the following:
import rpy2
import rpy2.robjects as RObjects
from rpy2.robjects.packages import importr
princurve = importr('princurve', robject_translations = {"plot_principal_curve": "plot.principal.curve"})
princurve = importr('princurve', robject_translations = {"points_principal_curve": "points.principal.curve"})
and got this error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\me\AppData\Local\Continuum\anaconda3\lib\site-packages\rpy2\robjects\packages.py", line 498, in importr
symbol_resolve=symbol_resolve)
File "C:\Users\me\AppData\Local\Continuum\anaconda3\lib\site-packages\rpy2\robjects\packages.py", line 202, in __init__
self.__fill_rpy2r__(on_conflict=on_conflict)
File "C:\Users\me\AppData\Local\Continuum\anaconda3\lib\site-packages\rpy2\robjects\packages.py", line 328, in __fill_rpy2r__
.__fill_rpy2r__(on_conflict=on_conflict))
File "C:\Users\me\AppData\Local\Continuum\anaconda3\lib\site-packages\rpy2\robjects\packages.py", line 238, in __fill_rpy2r__
exception)
File "C:\Users\me\AppData\Local\Continuum\anaconda3\lib\site-packages\rpy2\robjects\packages_utils.py", line 120, in _fix_map_symbols
raise exception(msg)
rpy2.robjects.packages.LibraryError: Conflict when converting R symbols in the package "princurve" to Python symbols:
-lines_principal_curve -> lines.principal.curve, lines.principal_curve
- plot_principal_curve -> plot.principal.curve, plot.principal_curve
- points_principal_curve -> points.principal.curve, points.principal_curve
To turn this exception into a simple warning use the parameter `on_conflict="warn"`
can anyone help?
Upvotes: 1
Views: 284
Reputation: 15379
You were almost there! In robject_translations
you need to provide R name -> Python name mapping, but your dictionary seemed to be the other way around. You also need to have all the mappings in a single dictionary. To make it super clear, you can resolve the conflicts like this:
princurve_example_1 = importr(
"princurve",
robject_translations={
"plot.principal.curve": "plot_dot_principal_dot_curve",
"lines.principal.curve": "lines_dot_principal_dot_curve",
"points.principal.curve": "points_dot_principal_dot_curve",
# optional (if omitted, you will get them under plot_principal_curve, etc.):
"plot.principal_curve": "plot_dot_principal_curve",
"lines.principal_curve": "lines_dot_principal_curve",
"points.principal_curve": "points_dot_principal_curve"
}
)
# then, after creating the curve and storing it in curve variable:
princurve_example_1.plot_dot_principal_dot_curve(curve)
# or
princurve_example_1.plot_dot_principal_curve(curve)
However, after consulting the pincurve documentation I see that the principal.curve
is deprecated and you should use principal_curve
instead (good to see more R packages finally moving to the convention of using underscores in function and variable names when possible!); therefore you can just do:
princurve = importr(
"princurve",
robject_translations={
"plot.principal.curve": "plot_principal_curve_deprecated",
"lines.principal.curve": "lines_principal_curve_deprecated",
"points.principal.curve": "points_principal_curve_deprecated",
}
)
# auto-generated from "plot.principal_curve"
princurve.plot_principal_curve(curve)
# manually mapped from "plot.principal.curve"
princurve.plot_principal_curve_deprecated(curve)
Upvotes: 2