sys.call() 's srcref doesn't match the language

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

sys.call() 's srcref doesn't match the language

Antoine Fabri
Dear R-devel,

I found this behavior disturbing, if `1 + f()` is called, `sys.call()`
called inside of `f` will return a quoted `f()` with a "srcref" that prints
"1 + f()".

I don't know which one is good but I don't think they can be correct at the
same time.

Here's a reproducible example:

f <- function(){
  sc <- sys.call()
  print(sc)
  attr(sc, "srcref") <- NULL
  print(sc)
  1
}
f2 <- function() {
  1 + f()
}
f()
#> f()
#> f()
#> [1] 1
f2()
#> 1 + f()
#> f()
#> [1] 2

Best,

Antoine

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: sys.call() 's srcref doesn't match the language

Lionel Henry
Hello,

The source references are useful for debugging tools because they
allow linking to call sites in the source files.

I agree the output can be confusing. Perhaps this could be fixed by
tweaking the print method for calls. If the deparsed call doesn't
match the srcref, both could be displayed along with file:line:column.

```
#> f()
#> <srcref:file.R:2:3>
#> 1 + f()
```

Best,
Lionel


On 9/2/20, Antoine Fabri <[hidden email]> wrote:

> Dear R-devel,
>
> I found this behavior disturbing, if `1 + f()` is called, `sys.call()`
> called inside of `f` will return a quoted `f()` with a "srcref" that prints
> "1 + f()".
>
> I don't know which one is good but I don't think they can be correct at the
> same time.
>
> Here's a reproducible example:
>
> f <- function(){
>   sc <- sys.call()
>   print(sc)
>   attr(sc, "srcref") <- NULL
>   print(sc)
>   1
> }
> f2 <- function() {
>   1 + f()
> }
> f()
> #> f()
> #> f()
> #> [1] 1
> f2()
> #> 1 + f()
> #> f()
> #> [1] 2
>
> Best,
>
> Antoine
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: sys.call() 's srcref doesn't match the language

Antoine Fabri
Thanks Lionel,

I now understand what's going on. I like your proposal and I can confirm I
wouldn't have been confused had it be printed this way.

In fact I wouldn't mind the file:line:column to be displayed every time.

Best,

Antoine



Le jeu. 3 sept. 2020 à 00:19, Lionel Henry <[hidden email]> a écrit :

> Hello,
>
> The source references are useful for debugging tools because they
> allow linking to call sites in the source files.
>
> I agree the output can be confusing. Perhaps this could be fixed by
> tweaking the print method for calls. If the deparsed call doesn't
> match the srcref, both could be displayed along with file:line:column.
>
> ```
> #> f()
> #> <srcref:file.R:2:3>
> #> 1 + f()
> ```
>
> Best,
> Lionel
>
>
> On 9/2/20, Antoine Fabri <[hidden email]> wrote:
> > Dear R-devel,
> >
> > I found this behavior disturbing, if `1 + f()` is called, `sys.call()`
> > called inside of `f` will return a quoted `f()` with a "srcref" that
> prints
> > "1 + f()".
> >
> > I don't know which one is good but I don't think they can be correct at
> the
> > same time.
> >
> > Here's a reproducible example:
> >
> > f <- function(){
> >   sc <- sys.call()
> >   print(sc)
> >   attr(sc, "srcref") <- NULL
> >   print(sc)
> >   1
> > }
> > f2 <- function() {
> >   1 + f()
> > }
> > f()
> > #> f()
> > #> f()
> > #> [1] 1
> > f2()
> > #> 1 + f()
> > #> f()
> > #> [1] 2
> >
> > Best,
> >
> > Antoine
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> >
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: sys.call() 's srcref doesn't match the language

R devel mailing list
In reply to this post by Lionel Henry
>On Wednesday, September 2, 2020, 6:19:20 PM EDT, Lionel Henry <[hidden email]> wrote:
>
>Hello,
>
>The source references are useful for debugging tools because they
>allow linking to call sites in the source files.
>
>I agree the output can be confusing. Perhaps this could be fixed by
>tweaking the print method for calls. If the deparsed call doesn't
>match the srcref, both could be displayed along with file:line:column.
>
>```
>#> f()
>#> <srcref:file.R:2:3>
>#> 1 + f()
>```
>
>Best,
>Lionel

Why print the mismatched srcref at all?  I find that confusing.
Just omit the srcref from display. Debugging tools can
still retrieve it and use the information, presumably.

Best,

Brodie.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel