search for: srcref

Displaying 20 results from an estimated 115 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...
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...
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...
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...
2016 May 20
2
identical on closures
Specifically, the srcfile attribute of the srcref attribute of the two instances of the functions contain different environments, AFAICT. Environments are compared only by exact pointer, so this forces return FALSE. Snippets from .Internal(inspect(x)) and .Internal(inspect(y)): @cca008 03 CLOSXP g0c0 [MARK,NAM(2),ATT] FORMALS: @604b58 00 NILSX...
2011 Nov 19
0
Problems with new srcref warnings in R 2.14 (development)
Dear R developers, Print method for function now tries to open the source file associated with srcref of the function. It outputs only the warning, if file cannot be open, and forgets to print the function definition. Example: eval(parse(text = "tf <- function(a){ b <- a^4 b }", srcfile = srcfile("xxx at 17"))) > tf <srcref: file "xxx at 17" c...
2024 Mar 01
1
capture "->"
...<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...
2019 Jul 13
2
Mitigating Stalls Caused by Call Deparse on Error
...if(!(is.numeric(max.lines) && !is.na(max.lines) && +???????? as.integer(max.lines) > 0L) +??? ) { +??????? max.lines <- -1L +??? } +??? if(is.null(x) && !is.null(x <- get0(".Traceback", envir = baseenv()))) { +??????? for(i in seq_along(x)) { +??????????? srcref <- attr(x[[i]], 'srcref') +??????????? x[[i]] <- deparse(x[[i]], nlines=max.lines) +??????????? attr(x[[i]], 'srcref') <- srcref +??????? } +??? } ???? else if (is.numeric(x)) ??? ??? ?x <- .Internal(traceback(x)) ???? x @@ -26,7 +36,16 @@ ? ?traceback <- function(x =...