# Python + R: How much R do I need to know to use random R libraries in python Using Rpy2

I'm just getting into data science from a qualitative background, and I want to be able to do the most stuff with least amount of overhead. (mostly machine learning and agent based modeling).

I'm currently learning python, and would hate to switch languages in the middle of my coursera class mitx 6.00x. Also, I like that python is better for other stuff like scripting, data munging, NLP etc.

However, I am eventually going to need to use some R packages (probably) it seems.

Can I get away with learning only a minimum of R (how much and what exactly), if I learn pyhton + packages and use Rpy2 to access random R libraries, or would i still have to learn both languages fully?

• If you're going to be calling R you will need to know enough to give it the right arguments (which will require understanding the help, which takes a little practice) and to be able to process what it returns. Which means you'll need to understand the data types and some of the syntax of R. – Glen_b Dec 1 '13 at 21:17
• About know enough to give it the right arguments (which will require understanding the help, which takes a little practice): rpy2-2.4.0 will build Python docstrings on-the-fly (using the R help and/or introspection). – lgautier Dec 1 '13 at 22:55

You will need to know the differences between dataframes, matrices and lists. Also the differences between the R vector data types (logical, character, numeric, factor, list) and language types (formula, expression, function, call) and the situations under which they will be coerced to the next level in their type-hierarchies. (R is loosely typed and has a fair amount of invisible coercion.)

Various data-mining and text-mining packages have different conventions as to types of their expected inputs (and outputs). This is where @Glen_b's comments apply. The typical new user of R generally fails to read the Usage section of the R-help pages which are generally very specific if you pay attention to the various R object types. If using pandas, you may be able to easily transfer results from dataframes to the Python equivalent.

The extraction and assignment operators ("[", "[[", and "$") will require some careful study. There are a bunch of gotchas. (Avoid using attach and "$" if you can. Anything that can be done with "\$" can be done with "[[".)

Python is today very well suited for Data Analysis, Machine Learning and related fields. Please refer to packages such as:

Answering the question, you should not invest time learning R for the moment if you already know Python, that's my opinion.

• I agree that python is quite good for data analysis, but I see myself needing to use some R libraries... How much R knowledge would it take just to do that from within python? – taiidan Dec 1 '13 at 20:28
• How much depends on your purposes, the time you have to spend, etc. I would recall to R only if Python is too far from your ultimate goal. Perhaps if you list the algorithms you intend to use, someone will help you out. – juliohm Dec 1 '13 at 20:38

As answered by @Glen_b in the comments, you'll likely need to read the documentation for the R functions you will be using. This is generally valid for calling Python functions.

Otherwise rpy2 is exposing R and its packages as if they were Python libraries.

Finally, learning rudiments of two languages is not necessarily a bad idea, particularly when both of them are widely used.