3 ms·
> Watch how its attempt at lexical scope combines with lazy evaluation for ridiculous fun. qplot(hp, mpg, data=subset(mtcars, mpg<30), shape
by jjoonathan 13y ago
> Watch how its attempt at lexical scope combines with lazy evaluation for ridiculous fun.
qplot(hp, mpg, data=subset(mtcars, mpg<30),
shape=as.factor(cyl),
color=am,
facets=gear~cyl)
vs
mtbadcars <- subset(mtcars, mtcars$mpg<30)
qplot(mtbadcars$hp, mtbadcars$mpg,
shape=as.factor(mtbadcars$cyl),
color= mtbadcars$am,
facets=(mtbadcars$gear)~(mtbadcars$cyl))
Why thanks, I do find it ridiculously fun to use short, readable names while maintaining encapsulation so that I can 1) keep multiple versions of a dataset around 2) not prefix every reference to a column in the dataset with the dataset name, cluttering the argument list and requiring 20 replacements or a kludgy temporary variable every time I want to plot a different subset.
Oh wait, you were trying to convince me that was a bad thing?
- pseut 13y agoDid you write qplot? (rhetorical question) A lot of these "quirks" of R are nice for end users when they're implemented well, but are unintuitive to program and, as a consequence, are inconsistently implemented across packages. Hadley doesn't write everything, you know.
- jjoonathan 13y ago> Did you write qplot? (rhetorical question) Not sure what you're getting at. > A lot of these "quirks" of R are nice for end users when they're implemented well, but are unintuitive to program It's not a quirk, it's a core feature. It's used consistently and to great effect. Notice how the "subset" function takes advantage of the same flexibility. I'm about 95% sure neither the subset function nor the other standard library functions that use this "trick" were written by Hadley. The "trick" was expected to make expressions significantly easier to read and easier to write from the very beginning. It might surprise a few people who come from another language and think they've seen it all, but once they figure out what's going on (which should happen on the first tutorial or 2nd or 3rd copypaste) it'll be a pleasant surprise. Unless they kneejerk and hate on it because it's unusual among languages.
- pseut 13y agoIt's used consistently in the core language and in well written packages but very inconsistently across the ecosystem. I certainly don't use it in packages I write for my own use and it's pretty unused in most of the packages I download.