News for hackers. Stuff that matters.
Re:An opinionated view of the Tidyverse “dialect” of the R l... by nerdponx on Friday July 05, 2019 @11:44AM (#20363406)
The R standard library is kind of weird and hard to use for "general purpose" programming. It's very clearly a domain specific language.

Also, it's unbelievably slow for basic operations like looping, function calls, and variable assignment. It's literally orders of magnitude slower than Python (I've tested it). Unlike its fellow C-flavored-Lisp Javascript, R retains an extreme level of homoiconicity, Which apparently makes the language very difficult to compile or optimize. I don't know how e.g. SBCL does it, but over the lifetime of the R language no one has managed to implement a non-trivial subset of R that performs better than GNU R (fastR was never finished to my knowledge). So you are basically relegated to writing code in C, Fortran, or C++ if you need even decent performance. Otherwise you are stuck using "vectorized" operations like lapply(), which are fine but make for a jarring experience if you're coming from other languages.

So of course it's a "real" language in the sense that Bash is a real language. But it's ultimately and fundamentally a domain-specific scripting language and I don't know if there is a way around that.

Re:An opinionated view of the Tidyverse “dialect” of the R l... by vincent-toups on Friday July 05, 2019 @02:13PM (#20364529)
I can give you some sense of why one can compile SBCL and not R. SBCL and other Lisps these days maintain some kind of conceptual barrier between macroexpansion time and run time, so that you can _stage_ your activity appropriately. Read the code, gather the macro definitions, expand the code (repeat as necessary) until you have some base language without metaprogramming in it.

Then you can optimize and compile. This is particularly true of Scheme which foregoes much of the dynamic quality of Common Lisp in favor of a much more static view of the world. But its still basically true in CL.

R doesn't have macros of that kind. It has a sort of weird laziness based on arguments remaining unevaluated until needed. Metaprogramming in R is typically done by intercepting those "quoted" arguments and then evaluating them in modified contexts (this is exposed to the user more or less by letting them insert scopes into the "stack").

Thus, there is no distinction between macroexpansion and execution time. Hence, its tough to write a compiler, which is basically just a program which identifies invariants ahead of time and pre-computes them (eg, lexical scope is so good for compilers because you can pre-compute variable access). Because all sorts of shenanigans can be got up to by walking quoted expressions and evaluating them in modified contexts, R is hard to compile.

This is, by the way, why the `with` keyword was removed from Javascript. It provided exactly the ability to insert a scope into the stack used to look up variable bindings.

Re:An opinionated view of the Tidyverse “dialect” of the R l... by goatlover on Friday July 05, 2019 @06:08PM (#20366281)
I didn't think the with statement was removed, as that would break backwards compatibility on the web with any older code that used it. Instead, it's just not allowed under strict mode, but it is still part of the ECMAScript specification. I just tried it in the Chrome console, and it still works.
Re:An opinionated view of the Tidyverse “dialect” of the R l... by lispm on Friday July 05, 2019 @05:47PM (#20366147)
> This is particularly true of Scheme which foregoes much of the dynamic quality of Common Lisp

The idea of even the standard Common Lisp is that both is possible: a static Common Lisp and a dynamic Common Lisp, even within the same application in different sections of the program. Common Lisp allows hints to the compiler to remove various features (like fully generic code being reduced to type specific code), it allows a compiler to do various optimizations (inlining, getting rid of late-binding, ...) - while at the same time other parts of the code might be interpreted on the s-expression level.

Re:An opinionated view of the Tidyverse “dialect” of the R l... by vincent-toups on Saturday July 06, 2019 @07:36AM (#20369141)
Its definitely the idea. I know it works well enough for a lot of people, but for me, I'm happy to just give up on the dynamic behavior in favor of a simpler universe.

The last thing I want to be thinking about is whether my compiler needs a "hint" that something can be stack allocated, for instance. That is their business, not mine.

Re:An opinionated view of the Tidyverse “dialect” of the R l... by lispm on Saturday July 06, 2019 @02:40PM (#20371113)
Common Lisp as a language standard makes no commitment to the smartness of a compiler. If a certain compiler can figure out things, great, but some compilers might be dumb by design (for example to be fast for interactive use). That's left to implementations.
Re:An opinionated view of the Tidyverse “dialect” of the R l... by Bootvis on Friday July 05, 2019 @12:46PM (#20363903)
The standard lib is limited for general programming, but many standard libraries are and often don’t have a package repository as good as CRAN.

It seems the Graal people managed to make R quite fast and is still being developed. Is there another faster? Any way, check out my blog post:

http://bootvis.nl/fastr-sudokus/

However, fastR is not a drop in replacement yet.

In any case, for me professionally, R slowness is never a problem. data.table does the heavy lifting.

What is a confusing mess, is the object system.

Re:An opinionated view of the Tidyverse “dialect” of the R l... by sarah180 on Friday July 05, 2019 @09:52PM (#20367232)
it's ultimately and fundamentally a domain-specific scripting language

A domain-specific rather than general-purpose programming language? Most definitely. A scripting language? I would dispute that. Scripting languages are for automating the execution of sequences of tasks that you'd otherwise run independently.

Re:An opinionated view of the Tidyverse “dialect” of the R l... by kgwgk on Friday July 05, 2019 @12:11PM (#20363609)
Are you aware of Radford Neal’s pqR? https://radfordneal.wordpress.com/
Re:An opinionated view of the Tidyverse “dialect” of the R l... by nerdponx on Friday July 05, 2019 @01:06PM (#20364050)
I had heard of it in the past but I didn't realize it was in a finished state and keeping pace with recent R versions. I'll read up on it, thank you.

Edit: looks like it's still a full major version behind? To be fair, there weren't many significant changes between R 2.x and 3.x.

Re:An opinionated view of the Tidyverse “dialect” of the R l... by kgwgk on Friday July 05, 2019 @01:30PM (#20364207)
Well, it may not be keeping up with the new versions but at least it does cover a non-trivial subset of the standard implementation. :-)

I have not tried it in many years and I don't know how much faster or compatible it is. Nevertheless, I think it's a good thing that an "outsider" is looking at performance issues.

As far as I know it's essentially a one-man's effort. One could imagine that RStudio or Microsoft would be able to improve R performance substantially if they wanted to.

Re:An opinionated view of the Tidyverse “dialect” of the R l... by lottin on Friday July 05, 2019 @12:21PM (#20363679)
To say that R is a domain-specific language is hardly a criticism, though. It was designed to be domain-specific from the start.
Re:An opinionated view of the Tidyverse “dialect” of the R l... by mbreese on Friday July 05, 2019 @04:45PM (#20365749)
I’d say one of the major problems I have with R is when people try to use it as a general purpose language. Just because you can doesn’t mean you should. It just wasn’t designed that way. I’ve seen a lot of R code that would have been trivial to write and execute significantly faster in another language.

But for its domain, I think R is great.

I guess when all you have is a hammer...