From georgi@bo@hn@kov @ending from m@nche@ter@@c@uk  Wed Jun 20 14:03:39 2018
From: georgi@bo@hn@kov @ending from m@nche@ter@@c@uk (Georgi Boshnakov)
Date: Wed, 20 Jun 2018 12:03:39 +0000
Subject: [Rd] 
 incomplete results from as.character.srcref() in some cases
 involving quote()
In-Reply-To: <ab568749-f10b-6aa2-b690-8769c0a18c37@gmail.com>
References: <438D2EC9EAFE5946B2D5864670EA468E018F65DC48@MBXP01.ds.man.ac.uk>
 <ab568749-f10b-6aa2-b690-8769c0a18c37@gmail.com>
Message-ID: <438D2EC9EAFE5946B2D5864670EA468E018F65DFE2@MBXP01.ds.man.ac.uk>

Thanks for looking into this and sorry for the noise. I should have realised that the outermost quote() in my examples is not part of the parsed expression.  

Best,
Georgi

-----Original Message-----
From: Tomas Kalibera [mailto:tomas.kalibera at gmail.com] 
Sent: 20 June 2018 11:01
To: Georgi Boshnakov; r-devel at r-project.org
Subject: Re: [Rd] incomplete results from as.character.srcref() in some cases involving quote()

wholeSrcref attribute is documented in ?parse to be the source reference 
corresponding to the already parsed text. The implementation in the 
parser matches the documentation - the code stops at the last 
byte/character of the expression, that is, on the closing brace - which 
is the "already parsed text". I think this works as documented (also 
source() uses the current implementation of wholeSrcref).

Best
Tomas

On 06/18/2018 04:20 PM, Georgi Boshnakov wrote:
> Hi,
>
> The result of  as,character() on  'srcref' objects doesn't have the closing ')' in some cases involving 'quote':
>
>> e4 <- quote({2+2})
>> class(attr(e4, "wholeSrcref"))
> [1] "srcref"
>> as.character(attr(e4, "wholeSrcref"))
> [1] "e4 <- quote({2+2}"
>
> As a result printing the object also lacks it and gives an incomplete expression:
>
>> attr(e4, "wholeSrcref")
> e4 <- quote({2+2}
>
> It seems that it is the top level quote that suffers from this. Here the inner 'quote' has the matching ')' but the outer one doesn't:
>
>> e5 <- quote({quote({2+2})})
>> class(attr(e5, "wholeSrcref"))
> [1] "srcref"
>> attr(e5, "wholeSrcref")
> e5 <- quote({quote({2+2})}
>> as.character(attr(e5, "wholeSrcref"))
> [1] "e5 <- quote({quote({2+2})}"
>> attributes(e5)
> ...
>
> $wholeSrcref
> e5 <- quote({quote({2+2})}
>
>
> Attribute 'wholeSrcref' seems undocumented but it is of class 'srcref' which is documented (eg ?srcref) and has supporting methods.
>
>
> Georgi Boshnakov
>
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel




[Rd] incomplete results from as.character.srcref() in some cases involving quote()
Georgi Boshnakov