vubiostat/brew — pull request #1 by klmr (2014-10-13 15:19:37+00:00)
Title: Brew breaks when redefining common functions

Due to scoping, Brew breaks when the user has redefined any of several common functions. Our particular case occurs because we are redefining the [`<-` operator](https://gist.github.com/klmr/25dc765211c59bb749b0) but the problem will also occur for any other function that is used inside `.brew.cached`, because `.brew.cached` is injected into (a namespace inheriting from) the global namespace, rather than being executed in its proper package namespace.

Here’s an MWE to illustrate the problem:

```r
library(brew)
# Redefine a function used in `.brew.cached`
exists = function (df, x) x %in% rownames(df)
brew('test')
brew(text = 'test')
# Error in exists(".brew.cat", envir = envir) :
# unused argument (envir = envir)
```

The problem, as I’ve said, is that `.brew.cached` is injected into the user namespace, thus subverting the R package namespace mechanism, which is designed to avoid this kind of name clashes. Unfortunately, the nature of Brew doesn’t make it trivial to fix this.

The attached PR fixes this by undoing the environment injection, and instead using explicit environment accesses, where required.