I was bothered by one thing when I created the containers last week. The “doBy” package required a lot… And was only marginally useful to me.
For ONE rather simple function, “which.maxn()”, I was loading the doBy package. Just because I looked for a quick solution to a simple problem and ended up with that, kinda by default. But that package loaded quite a few others, and needed cmake (from the Linux box, in that case). LOTS, that is, additional stuff, actually *almost 40MB in the resulting image*, for just one simple function.
Why? NO excuse, I was just lazy. But I swore to myself to look into this last week, and then inspired by someone on LinkedIn who does nice stuff with no packages whatsoever… I started working towards getting rid of that dependency (and all its dependencies in turn), and this is the result:
Turns out, it was as simple as knowing that R base’s “sort()” function can return indices! That was it:
my_which.maxn <- function(vec, n) { sort(vec, decreasing = TRUE, index.return = TRUE)$ix[1:n] } my_which.minn <- function(vec, n) { sort(vec, index.return = TRUE)$ix[1:n] }
Which of course I found out looking for a better alternative which as usual appeared on StackOverflow. I did try to come up with my own code first, but not knowing about this sort() option, I ended up with something unnecessarily complex and so I reverted to this alternative in the end.
Resources
I recommend to check this, it’s instructive: StackOverflow about all that can be one simple function