6 ms·
Out of curiosity, what was the motivation for switching from Python to R for analysis, was there a particular R package that you were looking to use?
by thearn4 9y ago
Out of curiosity, what was the motivation for switching from Python to R for analysis, was there a particular R package that you were looking to use?
- jjn2009 9y agoI can't speak for top comment but I started learning R and realized that a lot of the primitives which are exposed in python as libraries are just primitives in R and are thus are more natural to use in subtle ways. Once you start thinking in R you think in data and statistics rather than how you deal with data and statistics within a language. This doesn't mean one is actually better than the other unless you want to do generic programing things along your math oriented code then probably python is better but I find this change of mental state to be useful when focusing on problems R is suppose to solve.
- int_19h 9y agoR has some really crazy metaprogramming facilities. This might sound strange coming from Python, which is already very dynamic - but R adds arbitrary infix operators, code-as-data, and environments (as in, collections of bindings, as used by variables and closures) as first class objects. On top of that, in R, argument passing in function calls is call-by-name-and-lazy-value - meaning that for every argument, the function can either just treat it as a simple value (same semantics as normal pass-by-value, except evaluation is deferred until the first use), or it can obtain the entire expression used at the point of the call, and try to creatively interpret it. This all makes it possible to do really impressive things with syntax that are implemented as pure libraries, with no changes to the main language.
- lottin 9y agoQuite true. R was originally build on top of Lisp and it shows in many places, such as in the metaprogramming stuff that you mention. Overall R seems a little weird at first but the more you get to know the language the more you realise it's actually pretty well thought out.
- peatmoss 9y agoIt's true, the more I do in R, the more I wish that it had remained scheme compatible (originally, R was built on a scheme if I remember correctly). My someday project is `#lang arcket` for Racket, which would allow people to use existing R code, and mix with Racket, with appropriate data.frame data structures and whatnot.
- int_19h 9y agoThe problem will likely be similar to that with alternative Python implementations - because so many existing libraries in the ecosystem are written in C, an implementation that is not ABI-compatible with them is not attractive to most existing users.
- peatmoss 9y agoNo fundamental reason I know of that the C libraries for R could be used with Racket as well. After all, both R and Racket are able to do the FFI dance. Could the hypothetical R-in-Racket implementation sufficiently mimic the R FFI as to allow all R code to run without modification? Probably, maybe?
- peatmoss 9y ago* could not be used
- int_19h 9y agoThat's exactly the problem. R has a very specific API for its extensions - it's not just vanilla C, it's stuff like SEXP. Although now that I think more about it, it's not quite as bad as Python, because the data structures are mostly opaque pointers (at least until someone uses USE_RINTERNALS - which people do sometimes, even though they're not supposed to), so all operations have to be done via functions, where you can map them accordingly. You'd also need to emulate R's object litetime management scheme with Rf_protect etc; but that shouldn't be too difficult, either. Some more reading on all this: https://cran.r-project.org/doc/manuals/r-release/R-exts.html#System-and-foreign-language-interfaces https://cran.r-project.org/doc/manuals/r-release/R-exts.html... http://adv-r.had.co.nz/C-interface.html http://adv-r.had.co.nz/C-interface.html
- dnautics 9y agoyou should see Julia. There's a lot of syntactic sugar that borrows from the best of other languages, for example the pipe |> operator from elixir and do...end block syntax from ruby. Full unicode is supported. Unicode pi is implemented to mean the pure mathematical entity, so at compile-time it is turned into an memory reference to the most possible exact value. The metaprogramming in julia is so good I wrote a verilog DSL that transpiles specially written julia into compilable and verifiable verilog - in 3 days.
- int_19h 9y agoYep, I'm aware of Julia. I hope it takes off - it certainly looks a lot better thought out than R, which is very idiosyncratic. So far, though, it's still a fledgling.
- minimaxir 9y agoI had a similar story. I used R for statistics at college, but only base R, and it is verbose even for basic data manipulation. The scripts I made for my older data blog posts are effectively incomprehensible to me now. I ended up learning how to use Python/pandas/IPython because I had had enough and wanted a second option on how to do data analysis. Then the R package dplyr was released in 2013, alleviating most annoyances I had with R. dplyr/ggplot2 alone are strong reasons to stick with the R ecosystem. (not that Python is bad/worse; as I mention at the post, both ecosystems are worth knowing)
- newen 9y agoSame story. I use data.table and ggplot2, with a couple of dplyr functions, for pretty much all of my plotting and analysis now.
- bsg75 9y agoI use both, but R for interactive analysis and reporting, Python for data transformations (ETL). While the syntax of Python is "cleaner" for backend scripts, R feels more straightforward when working with dataframes (dplyr) resulting in things to report on. The syntax for ggplot2 fits the same category. As much as having one languages for both categories would be nice, using both today seems like a better option.