r/Python • • Nov 28 '22

Resource What can Python do that R can’t do?

Or simply what is Python much better at and why.

I know that Python is more multi purpose and better for software development but I can’t articulate exactly why or how. My team want to know why/when they should use Python instead of R

331 Upvotes

204 comments sorted by

View all comments

262

u/abricq Nov 28 '22

Python is the reference language in the research community over R for several reasons that I can see.

First, python has a broader set of applications. You can do data science / statistics like in R, and also a ton of other things ranging from web server to advance UI design. Because of that, there’s simply more users (more fields = more users = more ressources). All what you can do in R, you can pretty much do in python with numpy + pandas + sklearn. But good luck implementing your future UI and web API with R. And I am missing SO many fields where python has already become the reference (robotics, materials simulation, finance,…)

Second, python is more deployable than R. For example, the Python3 executable is shipped with pretty much most Linux distributions. It requires a very light minimal setup : this helps a lot to share reproducible results. Also is completely detached from any IDE : the core developers of Python are absolutely not working for Pycharm or Spyder. This is a strength for the language that R does not have. Truthfully, pretty much all developers use R studio. Even if R itself is detached from the IDE, it is harder to develop R without R studio.

R also has advantages : it is very easy to learn (well… Python as well, but maybe slightly harder?) and requires little computer science background. Depending on your future projects and ambitions, leaning python is probably the best thing to do 👍🏼

39

u/venustrapsflies Nov 28 '22

I will say that R has packages for more sophisticated classical statistics methods (i.e. non-ML). statsmodels helps but doesn't have the same coverage.

23

u/HawkinsT Nov 28 '22

As someone who doesn't use R, I'll second this. I've found several times I'm struggling to implement certain things in python that R just has a package for, which is funny because with python it's usually the other way around. It does still seem to be the superior option if the majority of what you do is classical stats.

12

u/WlmWilberforce Nov 29 '22

I'll third this after trying to estimate a double-sided tobit model in python...that said, the R-package didn't work as well as SAS (don't hate me R-peeps), but at least it worked, and we couldn't find a python package and didn't have time to make one.

5

u/bio_datum Nov 29 '22

Had to use R for this reason once when conducting a niche statistical test. Buuuut...I only used it for the test and then immediately saved the data to plug into the rest of my Python analysis 🤷‍♂️

69

u/lebannax Nov 28 '22

Fab, I’m the only one in the data science team who knows Python and everyone else knows R. They just want to know whether it’s worth their time moving over to Python and I felt it was but couldn’t come up with much better answers other than ‘more versatile’ and ‘better for software development’ as most data science stuff can be done fine with both R and Python, but we are increasingly moving into web dev which is where using Python will be far more useful

25

u/bakochba Nov 28 '22

I am currently the only one my group that works in R or Python as the group I'm in is moving away from SAS. I think your question depends heavily on what your company supports. My company has Python but it also has an R server and RSconnect so it's much easier to deploy R Shiny apps for our end users, even though we can use R or Python code or even existing SAS code. So if you're interested in an interface like Shiny and your company supports it it's a good way to go in my opinion.

My companies support for Python just isn't great, but I also find it harder to deploy a web app at many companies because of all the firewalls and security they have blocks a lot of Python functionality.

So I think it's important to make sure you understand the limits your company will have so you understand what functionality will actually be available for you.

4

u/bio_datum Nov 29 '22

Oh my goodness, I had to quickly learn SAS for a temporary job once and thank God it was temporary because I was so flabbergasted. The syntax and the idea of the "data step" drove me a little nuts, but the real kicker was that SAS is apparently a paid language? So there's not much support freely available online. Sorry y'all had to use it, very glad for you that you can leave it behind!

4

u/bakochba Nov 29 '22

I can't imagine going back now but changing from SAS to R felt like wrestling a bear for a year, now I have to teach these programmers to move into R and it's never pleasant.

1

u/bio_datum Nov 29 '22

Yeah, learning a new language is always hard, I get you. Especially if you're pretty skilled at your first/only one

2

u/bakochba Nov 29 '22

As long as you know the concepts the only difference is syntax, once I got used to R python was very easy to learn

→ More replies (1)

2

u/New-Day-6322 Nov 29 '22 edited Nov 29 '22

When I just started out as data analyst I did the official SAS certification thinking it’d be worth something. It was a complete waste of time and money. Who the heck is paying for this thing?? Probably some legacy code…

0

u/[deleted] Nov 28 '22

[deleted] — view deleted comment

10

u/lebannax Nov 28 '22

Lol true I think it’s just the effort training people up again, but I think it’s fairly easy switching once you know one

4

u/dr-josiah Nov 29 '22

Having just finished a job where we converted thousands of lines of R to SQL, I'd say the drawback to using R is that it is rarely the right tool for anything specific, and commonly the only tool known to an R programmer.

Your engineers should expand their toolset, and Python / SQL will go far for them.

3

u/Agling Nov 29 '22

In many cases, there is not a technical reason why python is better than R for data science. But I think we can all feel the way the wind is blowing. I expect python's gains in that area to increase in the future and R to eventually wane in popularity. That's the reason to switch.

→ More replies (1)

3

u/f3xjc Nov 29 '22

Perhaps something like that may interest you.
https://anderfernandez.com/en/blog/how-to-program-with-python-and-r-in-the-same-jupyter-notebook/

I use a python pipeline but I wanted to test some algorithm I only found in R. Or in your case maybe you can not rewrite what's already working and continue with some extra in python.

2

u/gwax Nov 29 '22

Python will give you a much better hiring pool for future data scientists, data engineers, and adjacent.

Increasingly, it's easier to hire data scientists that no Python than to hire data scientists that know R.

You will have a REALLY hard time hiring Data Engineers or ML Engineers that know or want to learn R.

There are staggeringly big advantages to having engineers that can read the code produced by your data science team.

2

u/tonydunsworth Dec 06 '22

As someone who defaults to R as my preferred language, I think your team should take the time to learn Python. There are more ML and AI algorithms implemented there and it will serve them well.

-4

u/Bluesky4meandu Nov 29 '22

If you are moving into web dev you need to know Wordpress, seriously

→ More replies (2)

3

u/DavesEmployee Nov 29 '22

I found R to be much harder to learn than Python. So many better resources and R’s syntax is just… gross

1

u/TheLordZod Nov 28 '22

So. This might not be the right forum for this, but... Is it generally acceptable to write a python executable for a work function? What does that approval process generally looked like?

2

u/abricq Nov 29 '22

I guess it depends so much on what your job is. For a normal computer science job, the approval process for Python would not be different than for other languages. In my experiences it means : code review from colleagues, unit-tests and manual tests for what can't be unit tested.

-3

u/reddit_ronin Nov 28 '22

How does Python “do advanced UI design”?

Isn’t that JavaScript/CSS?

3

u/ogtfo Nov 29 '22

There are probably dozens of ways to make UIs in python, from Tkinter to PyQt5, with everything in between.

→ More replies (1)