Вопрос

I know basic python programming and thus want to stay on the python datasci path. Problem is, there are many R packages that appeal to me as a social science person. Can Rpy2 allow full use of any general arbitrary r package, or is there a catch. How well does it work in practice?

If Rpy2 is too limited, I'd unfortunately have to branch over to r, but I would rather not, because of the extra overhead.

Thanks Tai

Это было полезно?

Решение

Bring the presumed limitations on.

Rpy2 is, at its lower level (the rpy2.rinterface level), exposing a very large part of the R C-API. Technically, one can do more with rpy2 than one can from R itself (writing C extension for R would possibly be the only way to catch up). As an amusing fact,doing "R stuff" from rpy2 can be faster than doing the same from R itself (see the rpy2 documentation benchmarking the access of elements in an R vector).

The higher level in rpy2 (rpy2.robject level) is adding a layer that makes "doing R stuff" more "pythonic" (although by surrendering the performance claim mentioned above). R packages look like Python modules, has classes such as Formula, Factor, etc... to have all R objects as Python classes, has a conversion system to let one complex R structures can be mapped to Python objects automagically (see example with lme4 in the rpy2 documentation0, translates on the fly invalid R variable names ('.' is a valid character for variable names in R), create on the fly Python docstrings from R documentation.

Другие советы

I'd suggest you to use RPy2 with IPythons %rmagic.

However, RPy2 is not a replacement or port or R's library of statistical function to Python. It's basically a simple way to call R from within Python (an R interpreter is started in the background). You may pass basic data-structures between R and Python (numpy arrays etc.), but more specialized structures (R's zoo or xts objects for example) might cause problems.

In the end, you still need to know R's syntax etc. to use RPy2. It's nice to interact with the R-Objects in Python, but you still need to know a lot about the R-Objects.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top