similar to: parse(text=...) and the srcfile attribute

Displaying 20 results from an estimated 10000 matches similar to: "parse(text=...) and the srcfile attribute"

2006 Nov 25
2
Source references from the parser
I have just committed some changes to R-devel (which will become R 2.5.0 next spring) to add source references to parsed R code. Here's a description of the scheme: The design is done through 2 old-style classes. "srcfile" corresponds to a source file: it contains a filename, the working directory in which that filename is to be interpreted, the last modified timestamp of the
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
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>
2025 Jan 19
2
Parser For Line Number Tracing
Hi Duncan ? Wonderful. Thank you. Bug or no bug, I think it would be a huge improvement for user-friendliness if R printed the last line by default *every time* a script dies. Most computer languages do so. Should I file it as a request for improvement to the R code development team? Maybe R can be improved at a very low cost to the development team and a very high benefit to newbies.
2025 Jan 19
1
Parser For Line Number Tracing
On 2025-01-18 8:27 p.m., Ivo Welch wrote: > I am afraid my errors are worse! (so are my postings. I should have > given an example.) > > ``` > x <- 1 > y <- 2 > nofunction("something stupid I am doing!") > z <- 4 > ``` > > and > > ``` >> source("where-is-my-water.R") > Error in nofunction("something stupid I am
2025 Jan 19
3
[External] Re: Parser For Line Number Tracing
On Sun, 19 Jan 2025, Ivo Welch wrote: > Hi Duncan ? Wonderful. Thank you. Bug or no bug, I think it would be > a huge improvement for user-friendliness if R printed the last line by > default *every time* a script dies. Most computer languages do so. > > Should I file it as a request for improvement to the R code > development team? Maybe R can be improved at a very low cost
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 NILSXP g0c0 [MARK,NAM(2)] BODY: @cc9650 06 LANGSXP
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(*, "srcfile")=Classes
2025 Jan 20
2
[External] Re: Parser For Line Number Tracing
I've posted a patch to bugs.r-project.org that fixes the traceback() issue. It's not specific to findFun3; you get the same problem with errors from expressions like 1 + "a" In my testing, I occasionally saw cases where show.error.locations = TRUE didn't work. I'll try to track down a reproducible case, and perhaps a patch to fix it. Duncan Murdoch On
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
2025 Jan 20
1
[External] Re: Parser For Line Number Tracing
Sorry, I'm not seeing the first problem now: options(show.error.locations = TRUE) works fine. Not sure what I did wrong before. I'm still seeing `traceback()` failing to report the attempt to call nofunction(). I suppose this is because a context is never set up for the failed call. Perhaps findFun3 could set up a fake context so that traceback() adds one more entry? Duncan
2014 Mar 05
1
[PATCH] Code coverage support proof of concept
Hello, I submit a patch for review that implements code coverage tracing in the R interpreter. It records the lines that are actually executed and their associated frequency for which srcref information is available. I perfectly understands that this patch will not make its way inside R as it is, that they are many concerns of stability, compatibility, maintenance and so on. I would like to have
2016 Mar 13
1
formals(x)<- drops attributes including class
Just checking in to see whether it is intended or not that assigning new formals to a function/closure causes any attributes to be dropped: EXAMPLE: > fcn <- structure(function() {}, foo="foo", class=c("foo")) > str(fcn) function () - attr(*, "srcref")=Class 'srcref' atomic [1:8] 1 18 1 30 18 30 1 1 .. ..- attr(*, "srcfile")=Classes
2025 Jan 21
1
[External] Re: Parser For Line Number Tracing
And now I've found the elusive bug in show.error.locations = TRUE as well, and posted a patch for that too. Back to the original topic of this thread: I think most users should routinely use options(show.error.locations = TRUE) e.g. in their .Rprofile. That will often speed up bug fixes, especially if my patch is incorporated. Duncan Murdoch On 2025-01-20 5:56 p.m., Duncan Murdoch
2025 Jan 19
1
[External] Re: Parser For Line Number Tracing
understood. but, please, consider not people like me but unwary beginners and students of R. I have used R now for decades, and even I am baffled by it. Couldn't you make R code easier to debug not only for people like me (who can indeed tweak their environments) but also for novice users? On Sun, Jan 19, 2025 at 8:46?AM <luke-tierney at uiowa.edu> wrote: > > On Sun, 19 Jan
2023 Mar 30
1
removeSource() vs. function literals
Dear R-devel, In a package of mine, I use removeSource on expression objects in order to make expressions that are semantically the same serialize to the same byte sequences: https://github.com/cran/depcache/blob/854d68a/R/fixup.R#L8-L34 Today I learned that expressions containing function definitions also contain the source references for the functions, not as an attribute, but as a separate
2023 Mar 31
2
removeSource() vs. function literals
If you can afford a dependency on rlang, `rlang::zap_srcref()` deals with this. It's recursive over expression vectors, calls (including calls to `function` and their hidden srcref arg), and function objects. It's implemented in C for efficiency as we found it to be a bottleneck in some applications (IIRC caching). I'd be happy to upstream this in base if R core is interested. Best,
2017 Dec 11
1
possible bug in utils::removeSource - NULL argument is silently dropped
Dear R-Core Team, I found an unexpected behaviour in utils::removeSource (also present in r-devel as of today). --- # create a function which accepts NULL argument foo <- function(x, y) { if (is.null(y)) y <- "default foo" attr(x, "foo") <- y x } # create a function which utilizes 'foo' testSrc <- function() { x <- 1:3 x <- foo(x,
2025 Jan 19
1
[External] Re: Parser For Line Number Tracing
Arguably, R was not designed or evolved for truly novice users, nor really was Python or just about all computer languages. As they evolved and became in many ways more powerful, they tended to get ever less user friendly in the way you are asking for and gotten so bloated that many features are not familiar even to expert users. Compiled languages can have ways to keep track of what LINE of code
2010 Mar 12
1
problem with parse(text=quote(name))
Calling parse(text=quote(name)) or text=as.name("name") makes parse() prompt for input from the command line and then it returns a parse of the initial characters of 'name' (depending on how many characters were typed at the prompt). E.g., > parse(text=quote(myName)) ?1/3 expression(myN) attr(,"srcfile") <text> >