Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

How to use R package in python with importr package

Writer Sophia Terry

I'm working on a web application using Dash, and I would like to use arules and aruleViz from R within a python script to get a graph of association rules obtained by using an Aprioi algorithm.

I found the rpy2 package and I installed it using conda conda install rpy2 ,then I try to import some packages like base tools by:

from rpy2.robjects.packages import importr`
arules = importr("tools",)`

That was fine(the package was imported)

And when I use: arules = importr("arules",) or arules = importr("arulesViz",)

I got receive the following error:

RRuntimeError: Error in loadNamespace(name) : there is no package called ‘arulesViz’

I saw an option in the importrpackage (lib_loc=None). I'm not sure how can I change it.

If there is any way to solve this, or if you know of a package in python that will help me plot a graph with vertices (I know how to so that with matplot.lib library using scatter but i'm not happy with it) I would greatly appreciate the help!

Thank you!

2

1 Answer

R packages must be installed before rpy2 can hope to find them. rpy2's importr() relies on R's own package loading system.

If you are certain to have installed that package earlier, you might have installed it in different directory, in a previous R process, and your current R process does not know about that directory. The optional named argument lib_loc accepts the path to that directory (see the doc).

(Note that there is also a utility function to check if an R package is installed without loading it)

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.