The good thing about sharing your knowledge with people is that you always find yourself strangely inspired. That’s what happened to me the other day in a meeting with colleagues where we were looking at some issues we were having with a reporting format we created in R Markdown. I was trying to explain to them, in simple terms, the little I knew about how R’s search path works and how it accesses objects along that path. I typed
search() and got this all too familiar output
 ".GlobalEnv" "package:stats"  "package:graphics" "package:grDevices"  "package:utils" "package:datasets"  "package:methods" "Autoloads"  "package:base" >
Because of the size of my console window that day, I suddenly had an analogy for them.
I asked them to imagine that they were sitting at a desk with two drawers and suddenly started looking for a particular document. What would they do?
The first impulse would be to start from the tabletop. This represents
.GlovalEnv, otherwise known as the Workspace. If not found, one would look through the drawers on one side, one after the other – beginning from the top – and if still not found, one moves over to the other side, also starting from the top drawer.
This is exactly how R uses its search path. The last visible ‘drawer’ that it checks is the base environment, which is accessible with