[Rd] question about R_ParseVector function

Duncan Murdoch murdoch at stats.uwo.ca
Tue May 29 11:29:51 CEST 2007

Ev Whin wrote:
> Hi r-devel,
> The R_ParseVector has been changed in R-2.5.0, and there is a simple
> description about the 4th argument at
> http://stat.ethz.ch/R-manual/R-patched/NEWS, it says that:
> "R_ParseVector() has a new 4th argument 'SEXP srcfile' allowing source
> references to be attached to the returned expression list. "
> I do not quite understand the purpose of adding the 4th argument. Would some
> experts explain this function in details?

The 4th argument isn't used by the parser, but it is carried along and 
attached to the output as part of the source reference in a srcref 
attribute.  The normal use would be a srcfile() object, or NULL for nothing.

Source references are currently used instead of deparsing when 
available, so that if a user parses something like

x    <-    1 # comment
y    <-    2

the comment and strange formatting aren't lost when displaying the code.

In the long term, I hope to also be able to use the source references in 
a source level debugger:  they allow R to know where the code comes from 
as it is executing it, so the display could allow single stepping 
through the original source file, rather than through a deparsed version 
of the code.  It's also possible that run-time errors could report the 
location of the line of code that triggered them.

Duncan Murdoch

More information about the R-devel mailing list