Bug 14825 - Possibility to set srcref when evaluating an expr (of any kind)
Summary: Possibility to set srcref when evaluating an expr (of any kind)
Status: NEW
Alias: None
Product: R
Classification: Unclassified
Component: Misc (show other bugs)
Version: R-devel (trunk)
Hardware: All All
: P5 enhancement
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2012-02-24 15:42 UTC by Stephan Wahlbrink
Modified: 2012-02-27 04:49 UTC (History)
0 users

See Also:


Attachments
Patch using srcref attribute in do_eval (749 bytes, patch)
2012-02-24 18:56 UTC, Stephan Wahlbrink
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Wahlbrink 2012-02-24 15:42:44 UTC
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.
Comment 1 Stephan Wahlbrink 2012-02-24 18:56:15 UTC
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.
Comment 2 Duncan Murdoch 2012-02-27 04:49:59 UTC
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.
>