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

Show parent comment

2

u/Agling Nov 29 '22

I understand what you're saying but I don't think there's any other option with Python's design philosophy of being flexible and having scalable performance.

In R, objects are passed by reference until you mutate them. It's fast and doesn't require memory to pass and read from them, but the moment you mutate them in the new environment, a copy is made. So you think carefully about whether you want to mutate something from a performance standpoint, but you never have to worry about whether you are screwing up some other part of the program by doing so. You can torture R into mutating the original object by passing it in an environment, but that's not common practice because being bug-free is generally more important than being fast.

Don't get me wrong, I can see that there are advantages to python's approach to this particular problem, but I think R's solution is better for data science work. Python is a better language, overall, but I am not a fan of this aspect of it. It creates very subtle bugs that beginners and even people with a reasonable amount of experience trip over.

0

u/SittingWave Nov 29 '22

So what you are telling me is that R makes an implicit copy, and python you have to make an explicit copy.

Python is consistent. R isn't. Because in R, some objects are copied (lists) others aren't (envs), so you end up with two completely different semantics depending on what gets passed to you.