Mark.Bravington at csiro.au
2012-Jan-11 20:54 UTC
[Rd] parse( connection) and source-keeping
In R <= 2.13.x, calling 'parse( con)' where 'con' is a connection, 'options( keep.source)' is TRUE, and default 'srcfile' would preserve the source. In R >= 2.14.1, it doesn't.> tf <- tempfile() > options( keep.source=TRUE) > texto <- c( 'function() { # comment', '}') > parse( text=texto)expression(function() { # comment })> cat( texto, file=tf, sep='\n') > parse( file=tf)expression(function() { # comment })> parse( file( tf))expression(function() { })> parse( textConnection( texto))expression(function() { }) and yes I didn't bother closing any connections. My suspicion is that this change is unintentional, and it seems to me that the best option would be for 'connection' to work like 'text' does here, ie to attach a 'srcfilecopy' containing the contents. I didn't submit a bug report because the documentation (which hasn't changed in this respect) actually doesn't say what 'parse' should do with 'connection' (as opposed to 'text' or 'file') argument when 'getOption( keep.source)' is TRUE and 'srcfile' is NULL. [BTW it's also unstated which argument takes precedence if a non-default 'srcfile' argument is specified.] So some additional explanation is needed there at a minimum, but also a decision as to what the best behaviour would be. bye Mark Mark Bravington CSIRO CMIS Marine Lab Hobart Australia
On 12-01-11 3:54 PM, Mark.Bravington at csiro.au wrote:> In R<= 2.13.x, calling 'parse( con)' where 'con' is a connection, 'options( keep.source)' is TRUE, and default 'srcfile' would preserve the source. In R>= 2.14.1, it doesn't.Actually, it preserved the "source" attribute of the function if it could, but didn't add a srcref. Sometimes it would fail, giving a message like Error in parse(textConnection(texto)) : function is too long to keep source (at line 8812)> >> tf<- tempfile() >> options( keep.source=TRUE) >> texto<- c( 'function() { # comment', '}') >> parse( text=texto) > expression(function() { # comment > }) >> cat( texto, file=tf, sep='\n') >> parse( file=tf) > expression(function() { # comment > }) >> parse( file( tf)) > expression(function() { > }) >> parse( textConnection( texto)) > expression(function() { > }) > > and yes I didn't bother closing any connections. > > My suspicion is that this change is unintentional, and it seems to me that the best option would be for 'connection' to work like 'text' does here, ie to attach a 'srcfilecopy' containing the contents.Yes, that does sound like a good idea. Duncan Murdoch> I didn't submit a bug report because the documentation (which hasn't changed in this respect) actually doesn't say what 'parse' should do with 'connection' (as opposed to 'text' or 'file') argument when 'getOption( keep.source)' is TRUE and 'srcfile' is NULL. [BTW it's also unstated which argument takes precedence if a non-default 'srcfile' argument is specified.] So some additional explanation is needed there at a minimum, but also a decision as to what the best behaviour would be. > > bye > Mark > > Mark Bravington > CSIRO CMIS > Marine Lab > Hobart > Australia > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
Seemingly Similar Threads
- Segfault when parsing UTF-8 text with srcrefs
- file descriptor leak in getSrcLines in R 2.10.0 svn 48590
- Segfault when parsing UTF-8 text with srcrefs
- [External] Re: Segfault when parsing UTF-8 text with srcrefs
- Proper way to drop 'srcref' from an expression created via substitute(function() ...)?