search for: srcref

Displaying 20 results from an estimated 131 matches for "srcref".

Did you mean: srcreg
2018 Jun 18
2
incomplete results from as.character.srcref() in some cases involving quote()
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 prin...
2020 Sep 02
3
sys.call() 's srcref doesn't match the language
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 <- func...
2011 May 12
1
Recursively parsing srcrefs
Hi all, Is it possible to "recursively" parse srcrefs to match the recursive structure of the underlying code? I'm interested in this because it's the final step in allowing functions to modify other functions while preserving the original source. I've tried to make a bit of demo of what I want to do below, and I think I may uncovered a...
2009 Feb 12
1
Why is srcref of length 6 and not 4 ?
Hello, Consider this file (/tmp/test.R) : <file> f <- function( x, y = 2 ){ z <- x + y print( z ) } </file> I get this in R 2.7.2 : > p <- parse( "/tmp/test.R" ) > str( attr( p, "srcref" ) ) List of 1 $ :Class 'srcref' atomic [1:4] 1 1 4 1 .. ..- attr(*, "srcfile")=Class 'srcfile' length 4 <environment> and this in R-devel : > p <- parse( "/tmp/test.R" ) > str( attr(p, "srcref") ) List of 1 $ :Class 'srcre...
2012 Jul 05
1
Extracting srcref for S4 methods
Hi, on R version 2.15.1 (2012-06-22) (Platform: i686-pc-linux-gnu (32-bit)) sourced functions have srcref attached as an attribute. Are such data also available for S4 generics and methods? How? (See sample code below) Thank you. Bests, Renaud f <- textConnection( " f <- function(){} setGeneric('myfun', function(x, ...) standardGeneric('myfun')) setMethod('myfun'...
2024 Mar 01
1
capture "->"
On 01/03/2024 5:25 a.m., Dmitri Popavenko wrote: > Dear?Duncan, > > On Fri, Mar 1, 2024 at 11:30?AM Duncan Murdoch <murdoch.duncan at gmail.com > <mailto:murdoch.duncan at gmail.com>> wrote: > > ... > If you parse it with srcrefs, you could look at the source.? The parser > doesn't record whether it was A -> B or B <- A anywhere else. > > > Thank you, this gets me closer but it still needs a little push: > > > foo <- function(x) { > ? x <- substitute(x) > ? return(attr(x...
2009 May 21
3
file descriptor leak in getSrcLines in R 2.10.0 svn 48590
I noticed the following file descriptor leak when I couldn't remove a package unless I shut down the R session that had loaded and used it. The function that triggered the problem printed the output of a call to parse(). Each time one prints a srcref a connection is opened and not closed. It looks like it happens in as.character.srcref's call to getSrcLines, which has some logic I don't understand about closing 'srcfile' on exit only if !.is.Open(srcfile): > getSrcLines function (srcfile, first, last) { if (first > l...
2006 Nov 25
2
Source references from the parser
...urce file: it contains a filename, the working directory in which that filename is to be interpreted, the last modified timestamp of the file at the time the object is created, plus some internal components. It is implemented as an environment so that there can be multiple references to it. "srcref" is a reference to a particular range of characters (as the parser sees them; I think that really means bytes, but I haven't tested with MBCSs) in a source file. It is implemented as a vector of 4 integers (first line, first column, last line, last column), with the srcfile as an attribut...
2013 Dec 13
1
Proper way to drop 'srcref' from an expression created via substitute(function() ...)?
First, why does this expression have a 'srcref' element: > exprA <- substitute(function(x) a*x, list(a=2)) > print(exprA) function(x) 2 * x > str(as.list(exprA)) List of 4 $ : symbol function $ :Dotted pair list of 1 ..$ x: symbol $ : language 2 * x $ :Class 'srcref' atomic [1:8] 1 20 1 34 20 34 1 1 .. ..- attr...
2014 Jan 07
1
Why do methods of "initialize" have no "srcref" attribute as other S4 mehtods?
...t; another special comment for the argument + ){ + 2*arg + ### a description for the return value + } + ) [1] "myGen" we can get the whole function definition with comments back by the following snippet: > attr(getMethod("myGen","numeric"),"srcref") function # a function with comments in its source ### that are used to document it with inlinedocs (arg ##<< another special comment for the argument ){ 2*arg ### a description for the return value } > this also works for operators > setMethod("...
2013 Jun 24
0
sys.source() does not provide the parsing info to eval()
...eval(expr, envir, enclos) $ : language (function() print(str(sys.calls())))() NULL then: eval(parse(text=code)) > OUTPUT: Dotted pair list of 3 $ : language eval(parse(text = code)) $ : language eval(expr, envir, enclos) $ :length 1 (function() print(str(sys.calls())))() ..- attr(*, "srcref")=Class 'srcref' atomic [1:8] 1 1 1 42 1 42 1 1 .. .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x7f42951fc388> As you can see, when using eval() directly, the expression/call has the parsing information available in the &...
2024 Mar 01
1
capture "->"
On Fri, Mar 1, 2024 at 1:00?PM Duncan Murdoch <murdoch.duncan at gmail.com> wrote: > ... > I was thinking more of you doing something like > > parse(text = "A -> B", keep.source = TRUE) > > I forget what the exact rules are for attaching srcrefs to arguments of > functions, but I do remember they are a little strange, because not > every possible argument can accept a srcref attribute. For example, you > can't attach one to NULL, or to a name. > > Srcrefs are also fairly big and building them is slow, so I think we &gt...
2025 Jan 19
2
Parser For Line Number Tracing
...t; > > > and no traceback is available. > > Okay, I see. In that case traceback() doesn't report the line, but it > still is known internally. You can see it using the following function: > > showKnownLocations <- function() { > calls <- sys.calls() > srcrefs <- sapply(calls, function(v) if (!is.null(srcref <- attr(v, > > "srcref"))) { > srcfile <- attr(srcref, "srcfile") > paste0(basename(srcfile$filename), "#", srcref[1L]) > } else ".") > cat("Current call stack l...
2025 Jan 19
1
Parser For Line Number Tracing
...nction "nofunction" > ``` > > and no traceback is available. Okay, I see. In that case traceback() doesn't report the line, but it still is known internally. You can see it using the following function: showKnownLocations <- function() { calls <- sys.calls() srcrefs <- sapply(calls, function(v) if (!is.null(srcref <- attr(v, "srcref"))) { srcfile <- attr(srcref, "srcfile") paste0(basename(srcfile$filename), "#", srcref[1L]) } else ".") cat("Current call stack locations:\n") cat(sr...
2018 Jun 20
0
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...
2024 Mar 01
1
capture "->"
Dear Duncan, On Fri, Mar 1, 2024 at 11:30?AM Duncan Murdoch <murdoch.duncan at gmail.com> wrote: > ... > If you parse it with srcrefs, you could look at the source. The parser > doesn't record whether it was A -> B or B <- A anywhere else. > Thank you, this gets me closer but it still needs a little push: > foo <- function(x) { x <- substitute(x) return(attr(x, "srcref")[[2]]) } > fo...
2025 Jan 19
3
[External] Re: Parser For Line Number Tracing
...ceback is available. >> >> Okay, I see. In that case traceback() doesn't report the line, but it >> still is known internally. You can see it using the following function: >> >> showKnownLocations <- function() { >> calls <- sys.calls() >> srcrefs <- sapply(calls, function(v) if (!is.null(srcref <- attr(v, >> >> "srcref"))) { >> srcfile <- attr(srcref, "srcfile") >> paste0(basename(srcfile$filename), "#", srcref[1L]) >> } else ".") >> cat(&q...
2024 Mar 01
1
capture "->"
...urdoch.duncan at gmail.com > <mailto:murdoch.duncan at gmail.com>> wrote: > > ... > I was thinking more of you doing something like > > ? parse(text = "A -> B", keep.source = TRUE) > > I forget what the exact rules are for attaching srcrefs to arguments of > functions, but I do remember they are a little strange, because not > every possible argument can accept a srcref attribute.? For example, > you > can't attach one to NULL, or to a name. > > Srcrefs are also fairly big and building them...
2025 Jan 19
1
[External] Re: Parser For Line Number Tracing
Thanks for pointing out the options. Using options(show.error.locations = TRUE) works on Ivo's example, but it doesn't show a location if the error happens in a function that doesn't have srcrefs, because the known location isn't on the top of the stack. Perhaps TRUE (and maybe "top"?) should look back through the stack until it finds a known location, and report that, or another option (e.g. "highest"?) could be added to do that. And still I think traceback()...
2025 Jan 20
2
[External] Re: Parser For Line Number Tracing
...01-19 3:39 p.m., Duncan Murdoch wrote: >> Thanks for pointing out the options. Using >> >> options(show.error.locations = TRUE) >> >> works on Ivo's example, but it doesn't show a location if the error >> happens in a function that doesn't have srcrefs, because the known >> location isn't on the top of the stack. >> >> Perhaps TRUE (and maybe "top"?) should look back through the stack until >> it finds a known location, and report that, or another option (e.g. >> "highest"?) could be added to...