regression test + possible fix

Hello,

Following the issue I raised (https://github.com/hadley/devtools/issues/333), here's a reproducible example as a regression test, and a possible fix with code extracted from base::loadNamespace(). 

Cheers,
Karl