[Rd] Issue with getParserData in R3.0.0
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 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 parenttoken terminaltext 27 11 1 42 27 0 exprFALSE 14 11 1 13 14 27 exprFALSE 1 11 17 1 3 SYMBOL_FUNCTION_CALL TRUE abs_max 3 11 17 3 14 exprFALSE 2 18 18 2 14 '(' TRUE ( 4 19 19 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. Brian __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Issue with getParserData in R3.0.0
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 > > > 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 parenttoken terminaltext > 27 11 1 42 27 0 exprFALSE > 14 11 1 13 14 27 exprFALSE > 1 11 17 1 3 SYMBOL_FUNCTION_CALL TRUE abs_max > 3 11 17 3 14 exprFALSE > 2 18 18 2 14 '(' TRUE ( > 4 19 19 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 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Issue with getParserData in R3.0.0
Thanks that seems to work. It looks like other packages explicitly change this to FALSE, so I have to set this to TRUE for each function call. Is there any particular policy for packages that update this option? Should I restore the original value upon function exit? Warm Regards, Brian On Jan 14, 2013, at 9:34 AM, Duncan Murdoch wrote: > 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 > > > > > > 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 parenttoken terminaltext > > 27 11 1 42 27 0 exprFALSE > > 14 11 1 13 14 27 exprFALSE > > 1 11 17 1 3 SYMBOL_FUNCTION_CALL TRUE abs_max > > 3 11 17 3 14 exprFALSE > > 2 18 18 2 14 '(' TRUE ( > > 4 19 19 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 > __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Issue with getParserData in R3.0.0
On 13-01-14 7:49 PM, Brian Lee Yung Rowe wrote: Thanks that seems to work. It looks like other packages explicitly change this to FALSE, so I have to set this to TRUE for each function call. Is there any particular policy for packages that update this option? Should I restore the original value upon function exit? Options belong to the user, not to you. You should definitely save the old value and restore it when you're done. Duncan Murdoch Warm Regards, Brian On Jan 14, 2013, at 9:34 AM, Duncan Murdoch wrote: 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 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 parenttoken terminaltext 27 11 1 42 27 0 exprFALSE 14 11 1 13 14 27 exprFALSE 1 11 17 1 3 SYMBOL_FUNCTION_CALL TRUE abs_max 3 11 17 3 14 exprFALSE 2 18 18 2 14 '(' TRUE ( 4 19 19 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 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel