5 ms·
This is a really interesting post. I have to say the data science team at Stitchfix are clearly doing really good, applied work that is central to their busines
by dandermotj 10y ago
This is a really interesting post. I have to say the data science team at Stitchfix are clearly doing really good, applied work that is central to their business. It's so cool to see.
Here's a tip for any R users who read through the code and (like me) is pained by repetition. Instead of using
library(lubricate)
library(bts)
library(...)
Just use apply!
packages <- c("lubricate", "bts", "...")
lapply(packages, library, character.only = TRUE)
- GFK_of_xmaspast 10y agoThat doesn't seem to me to be a huge efficiency win.
- dandermotj 10y agoIn terms of managing packages in session, readability and keystrokes, I think it definitely wins out over successive library calls. It's common to have >5 packages in any one script, especially if you avoid base R like many do.
- huac 10y agoor library(pacman) pacman::p_load("lubridate", "bts", ...) with the added benefit of installing missing packages (I find this especially useful because my school's computer lab deletes user-installed packages weekly)
- RockyMcNuts 10y agoit's clever but is it more readable? these sorts of discussions, people who write blog posts about 'library' vs. 'require', kind of feel like 'R smell'. wouldn't it be better for a language to just take a list of libraries for import, maybe with a readable syntax? so... have we got to where Julia can re-use R packages yet?
- dandermotj 10y agoI understand where you're coming from, but these two lines are exactly 'taking a list of libraries for import'. packages is a character vector of package names, lapply is by definition 'list apply'. We're taking a list of packages and applying the library function on them. This seems complicated if you're not used to it but R is a functional language. Approaching R from this perspective makes it a powerful, flexible.
- tanlermin 10y agoCheck out rcall.jl