At moment srcref can be used only in combination with block "{" statements by using the srcref attribute. When evaluation other expressions, there is no simple way to provide the associated srcref. This can be used for example in the 'source' function when evaluating the parsed expressions. == Duncan Murdoch == > The best approach seems to be to add another > argument to the internal do_eval call to set > the srcref before evaluating the expression. An alternative -just an idea- could be to use srcref attribute for this case too. For example the 'parse' function already returns an expression list with the source references attached as attribute.
Created attachment 1275 [details] Patch using srcref attribute in do_eval The patch updates 'R_Srcref' with the source referenes attached to the expression in 'do_eval'. It directly works with 'source' without additional modifications, because the srcref is already copied smartly by the extract operator "expr[i]" to the single expressions. Instead of the new variable 'srcrefs', the variable 'x' could be reused in the patch.
On 12-02-24 9:42 AM, r-bugs@r-project.org wrote: > https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=14825 > > Summary: Possibility to set srcref when evaluating an expr (of > any kind) > Product: R > Version: R-devel (trunk) > Platform: All > OS/Version: All > Status: NEW > Severity: enhancement > Priority: P5 > Component: Misc > AssignedTo: R-core@R-project.org > ReportedBy: sw@wahlbrink.eu > Estimated Hours: 0.0 > > > At moment srcref can be used only in combination with block "{" statements by > using the srcref attribute. When evaluation other expressions, there is no > simple way to provide the associated srcref. The problem is that not all expressions can accept attributes, e.g. the expression NULL parses to the NULL object, and you can't put a srcref on that. This is why srcrefs are "one level up", being attached to the block rather than separately to each expression. It works with parse(text="NULL") because that returns a vector of language objects; the srcref is on the vector, not on the individual objects. This doesn't mean that we couldn't look for srcrefs on all language objects, but it does mean that users couldn't always place them there, and I'm reluctant to put in code that sometimes can't work. Duncan Murdoch > > This can be used for example in the 'source' function when evaluating the > parsed expressions. > > == Duncan Murdoch == >> The best approach seems to be to add another >> argument to the internal do_eval call to set >> the srcref before evaluating the expression. > > An alternative -just an idea- could be to use srcref attribute for this case > too. For example the 'parse' function already returns an expression list with > the source references attached as attribute. >