Data-Camp/datacampSCT — pull request #1 by robertzk (2014-05-17 19:32:07+00:00)
Title: fix called_functions unit testing by ensuring parse data is always present

There is an extremely pernicious bug wherein the internal R function `parse` returns the `parseData` correctly from a fresh console,

```R
attr( parse(text= "mean(x);plot(x)"), 'srcfile')$parseData
# [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15]
# [1,] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
# etc...
```

but does *NOT* when this is called from unit tests.

```R
attr( parse(text= "mean(x);plot(x)"), 'srcfile')$parseData
# NULL
```

The following pull request fixes this issue. Namely, the core problem is that the last line in R's internal `parse`,

```R
.Internal(parse(file, n, text, prompt, srcfile, encoding))
```

calls R's internal C `parse` function. As you can observe from the source code of this C function, [the 'srcfile' attribute is an environment which should contain a `parseData` member](https://github.com/SurajGupta/r-source/blob/91aaa43312da6b0e6906ef221fd7756dc0459843/src/main/gram.c#L5745).

However, during unit tests, all attributes are dropped from the output of this internal C function, resulting in a parse failure. The fix is to notice that the R `parse` function includes the line

```R
if (keep.source)
srcfile <- srcfilecopy(srcfile, text)
```

which is what is used to pre-create the environment `srcfile`, and that the default for this argument is `getOption('keep.source')`.

```R
head(parse)
# function (file = "", n = NULL, text = NULL, prompt = "?", keep.source = getOption("keep.source"),
# srcfile = NULL, encoding = "unknown")
```

Indeed, using a `browser()` within one of the unit tests shows that indeed `getOption("keep.source")` is `FALSE`, which is what is causing our problem. I am still unsure of what is changing this option. However, modifying `called_functions` to replace

```R
parseData = try(getParseData(parse(text = code)), silent=TRUE)
```

with the more direct

```R
parseData = try(getParseData(parse(text = code, keep.source = TRUE)), silent=TRUE)
```

fixed the failing unit tests by (in the background) restoring the previously dropped `parseData`.