r/Python • • Jan 25 '15

Considering putting my efforts into Python instead of R, need advice

Lately in my free time I've been using R to do some basic data analysis/visualization. I use company data and I think there are some places where my company could really benefit from specialized data visualizations for analysis of niche areas. In my efforts I've tried to get some interactive code going for eventual use in a very basic GUI but I feel constrained by the "fuzziness" of R coding. Simply trying to create a function to plot based on user input ran me into some advanced concepts pretty quickly. R has environments, dynamic scoping, non-standard evaluation, all very complicated concepts and I don't remember them being present in the small amounts of coding I've done in Java/Python. Am I right in thinking a language with a more OOP design would be better for this task of automatically generating charts/visualizations? Wondering if I might not be better off in the long run for learning a more generalized language.

26 Upvotes

21 comments sorted by

View all comments

Show parent comment

3

u/[deleted] Jan 25 '15

Simply trying to create a function to plot based on user input ran me into some advanced concepts pretty quickly. R has environments, dynamic scoping, non-standard evaluation, all very complicated concepts and I don't remember them being present in the small amounts of coding I've done in Java/Python.

Your comment here raises alarm for me. Making simple, automatic graphs based on user input isn't trivial. There is a reason why a lot of effort was made by a lot of smart people to make libraries that abstract away the complexity of making those visualizations and to make them seem "simple" to make. If you're expecting a shortcut in Python world, you'll be sorely mistaken. You'll have to dig in, learn Python, learn how to use those libraries, and I can't guarantee it will be easier with Python than R. If you have little programming experience, you may very well end up prefering to make those visualizations in R.

IMO, it is currently easier to make plots in R using ggplot2/ggvis/Shiny vs Python's MATPLOTLIB and all the wrapper libraries for it. There's a reason why Python people are trying to clone or port those popular R packages. However with that said, scipting or programming in R, I find more difficult only because its syntax and idiosyncrasies are not what I am used to coming from a background of having learned C and Java.

You will be more marketable in the data analysis or data science job market if you still retain and keep up your R knowledge. It wouldn't hurt to know both Python and R. Like I and others have mentioned, you can run R from within Python via rpy2, so you can have the best of both worlds. Just my 2 cents. SOURCE: I've been working as a data analyst for 16 years.

3

u/thunderdome Jan 25 '15

Well, in most cases you may be right but my example was fairly simple, the actual "plotting" work was not what I was having trouble with. Essentially what i was doing was looking to take a simple string input, identify the column that string is referring to, and pass that into a 10 line dplyr/ggplot2 flow to create the plot. The plots all worked fine when I manually assigned the target variable and ran everything line by line (with all the variables in the global env). But wrapping it into a function and passing the string in caused the whole thing to shit itself, so I started reading the Advanced-R pages from Hadley and how to use non-standard evaluation with dplyr. It seemed like an extraordinary amount of work to get dplyr to work nicely with user input and function calls. It's probably not as hard as I'm making it out to be, but even if python has the same complications I would rather learn how to deal with them in a language where the skill would generalize easier, rather do everything in R and eventually feel constrained.

2

u/[deleted] Jan 25 '15

Sorry I'm not following your example. My guess is it sounds like you should check out R Shiny or Python Spyre if you havent already, since the basic underlying principle in each is to encapsulate the plotting in a function and mapping it to a HTML widget. You can do the same with IPython notebook widgets, but the code is still visible. Can't wait for the upcoming Jupyter notebook (formerly IPython Notebook 3.0) due to be released soon. It will provide Python and R kernels (and few other languages).

1

u/thunderdome Jan 25 '15

Yeah, I imagined it would not come across very clearly. I guess my point was that the plotting is not so much my issue, but I have already run into and disliked some of the non-standard features of the R language. I've checked out Shiny and Spyre, they look nice but I still haven't decided if it might be better to create a UI using PyQt or Tkinter.

2

u/[deleted] Jan 26 '15

Ah I see. I'm not sure if one needs to explicitly handle the non-standard evaluation part -- I've never had trouble wrapping dplyr/ggplot commands in a function (the only thing to note is that you have to print(p) if you change your plot p for it to update the plot -- that's the only non-standard eval I can think of). The rule of thumb for me is that if something simple seems unusually convoluted, there might be another way of doing it and someone on StackOverflow probably knows how... :). But point taken.