From murdoch.duncan at gmail.com  Mon Jan 14 15:34:49 2013
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Mon, 14 Jan 2013 09:34:49 -0500
Subject: [Rd] Issue with getParserData in R3.0.0
In-Reply-To: <A40C54F1-6BE4-4469-BF23-DB094A214A88@muxspace.com>
References: <A40C54F1-6BE4-4469-BF23-DB094A214A88@muxspace.com>
Message-ID: <50F41789.2010408@gmail.com>

On 13-01-13 8:43 PM, Brian Lee Yung Rowe wrote:> Hello,
 >
 > I am migrating my package lambda.r to R3.0.0 and am experiencing some 
issues with the getParserData function (which replaces the parser 
package). Basically the function works in the R shell but fails when 
either called from RUnit or from R CMD check.
 >
 > I've narrowed it down to the function getSrcfile, which is returning 
different values depending on the code path. From the command line 
(works okay):
 >
 > debug: srcfile <- getSrcfile(x)
 > Browse[2]>
 > debug: if (is.null(srcfile)) return(NULL) else data <- srcfile$parseData
 > Browse[2]> srcfile
 > <text>
 >
 > When running from the Runit script I get this instead:
 > debug: srcfile <- getSrcfile(x)
 > Browse[3]>
 > debug: if (is.null(srcfile)) return(NULL) else data <- srcfile$parseData
 > Browse[3]> srcfile
 > NULL
 >
 >
 > Below is an example calling the getParserData from the command line:
 >> text <- "abs_max(a, b) %::% numeric:numeric:numeric"
 >> parse(text=text)
 > expression(abs_max(a, b) %::% numeric:numeric:numeric)
 >> getParseData(parse(text=text))
 >     line1 col1 line2 col2 id parent                token terminal    text
 > 27     1    1     1   42 27      0                 expr    FALSE
 > 14     1    1     1   13 14     27                 expr    FALSE
 > 1      1    1     1    7  1      3 SYMBOL_FUNCTION_CALL     TRUE abs_max
 > 3      1    1     1    7  3     14                 expr    FALSE
 > 2      1    8     1    8  2     14                  '('     TRUE       (
 > 4      1    9     1    9  4      6               SYMBOL     TRUE       a
 > ...
 >
 > The RUnit call from the command line is
 > 
runTestFile('/home/brian/workspace/lambda.r/inst/unitTests/runit.dispatching.4.R')
 >
 > and fails because of the NULL value of srcfile. The first line of the 
runit test file is
 >    abs_max(a, b) %::% numeric:numeric:numeric
 >
 > Any insights are appreciated.

I think in the case that is failing you just don't have any source info 
in the parse.  parse() only installs it if the "keep.source" option is 
TRUE, and the default for that is the result of interactive().  So when 
you are not interactive you don't get source info.

You can fix it by explicitly setting options(keep.source=TRUE).

Duncan Murdoch



[Rd] Issue with getParserData in R3.0.0
Duncan Murdoch