Please see the below MWE
generate_summ_code= function(...) {
code = substitute(list(...))[-1]
gpd = getParseData(parse(text = deparse(code)), includeText = TRUE)
print(gpd)
gpd
}
generate_summ_code(n = n())
If I run that in REPL I get the print out
> line1 col1 line2 col2 id parent token terminal text
> 10 1 1 1 5 10 0 expr FALSE n()()
> 6 1 1 1 3 6 10 expr FALSE n()
> 1 1 1 1 1 1 3 SYMBOL_FUNCTION_CALL TRUE n
> 3 1 1 1 1 3 6 expr FALSE n
> 2 1 2 1 2 2 6 '(' TRUE (
> 4 1 3 1 3 4 6 ')' TRUE )
> 7 1 4 1 4 7 10 '(' TRUE (
> 8 1 5 1 5 8 10 ')' TRUE )
However, if I put the code inside a file say code.r
and I do
Rscript code.r
or
R -e "source('code.r')"
It just returns NULL. There is nothing in the ?getParseData
that indicates that the behaviour should be different?
Is this a bug in Base R?