R – Implementing sort and/or search algorithms – where and why


From time to time have I come across manually implemented sort and/or search algorithms, instead of using language implemented algorithms. Most source code I've been looking into is written in Java, C# or PHP – but I'd guess this phenomenon is language agnostic.

Regarding regular data structures such as lists; Why and where do you implement your own algorithm? Ideological reasons? More memory efficient? Can't stand the idea of using built-in features? Java preferably uses mergesort (in Collections.sort()), which has some overhead when you compare it to quicksort as an example. If you have a favorite which you use on a regular basis for doing common tasks, you're more than welcome to submit it in your language of choice!

Best Solution

In C++ you can have a container with an array inside that is only searched by methods of the container. You can use some library implementation but then you'll have to provide a comparator class and that's the same amount of code as simply writing a for() loop. Why produce a new entity (comparator class) for such case?