Displaying 20 results from an estimated 3000 matches similar to: "sys.source() does not provide the parsing info to eval()"
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
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,
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
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
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
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,
2023 Mar 30
2
removeSource() vs. function literals
On 30/03/2023 10:32 a.m., Ivan Krylov wrote:
> 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
>
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 printing the object also lacks it and gives an
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". I think this works as documented (also
source() uses the current implementation
2024 May 28
2
Segfault when parsing UTF-8 text with srcrefs
Hi all,
When I run the following code, R segfaults:
text <- "?"
srcfile <- srcfilecopy("test.r", text)
parse(textConnection(text), srcfile = srcfile)
It doesn't segfault if text is ASCII, or it's not wrapped in
textConnection, or srcfile isn't set.
Hadley
--
http://hadley.nz
[[alternative HTML version deleted]]
2016 Oct 12
0
How to assign NULL value to pairlist element while keeping it a pairlist?
Michael, thanks for this info.
I've stumbled upon this in a case where I walk an R expression (the
AST) and (optionally) modifies it (part of the globals package). In R
expressions, a function definition uses a pairlist to represent the
arguments. For example,
> expr <- quote(function(x = 1) x)
> str(as.list(expr))
List of 4
$ : symbol function
$ :Dotted pair list of 1
..$ x:
2013 Oct 24
0
TR: problem with ecdf : "missing C_R_approxfun" message
Hi again, this is a follow-up of my previous post :
I've noticed that
> attr(first.list[[1]]$size.ecdf,"call") gives ecdf(test.moms[, "m.pxs"]) and that there is no "test.moms" field in my records (a local variable named test.moms was used inside a function, but it was stored under another name in the list, outside the function)
May this be the answer (and
2024 May 28
1
Segfault when parsing UTF-8 text with srcrefs
On 5/28/24 19:35, Hadley Wickham wrote:
> Hi all,
>
> When I run the following code, R segfaults:
>
> text <- "?"
> srcfile <- srcfilecopy("test.r", text)
> parse(textConnection(text), srcfile = srcfile)
>
> It doesn't segfault if text is ASCII, or it's not wrapped in
> textConnection, or srcfile isn't set.
Thanks, this is
2016 Oct 15
0
How to assign NULL value to pairlist element while keeping it a pairlist?
>>>>> Michael Lawrence <lawrence.michael at gene.com>
>>>>> on Wed, 12 Oct 2016 15:21:13 -0700 writes:
> Thanks, this was what I expected. There is a desire to
> eliminate the usage of pairlist from user code, which
> suggests the alternative of allowing for function
> arguments to be stored in lists. That's a much deeper
2024 May 30
1
[External] Re: Segfault when parsing UTF-8 text with srcrefs
I get an R error and no segfault:
> parse(textConnection(text), srcfile = srcfile)
Error in parse(textConnection(text), srcfile = srcfile) :
test.r:1:1: unexpected $end
1: ?
^
This is R 4.3.0, so maybe the bug has been introduced since then...
Version and system info:
> version
_
platform x86_64-pc-linux-gnu
arch x86_64
os linux-gnu
system
2016 Oct 12
2
How to assign NULL value to pairlist element while keeping it a pairlist?
Thanks, this was what I expected. There is a desire to eliminate the
usage of pairlist from user code, which suggests the alternative of
allowing for function arguments to be stored in lists. That's a much
deeper change though.
On Wed, Oct 12, 2016 at 12:31 PM, Henrik Bengtsson
<henrik.bengtsson at gmail.com> wrote:
> Michael, thanks for this info.
>
> I've stumbled upon
2016 Oct 19
0
How to assign NULL value to pairlist element while keeping it a pairlist?
On Wed, 19 Oct 2016, Henrik Bengtsson wrote:
> On Sat, Oct 15, 2016 at 2:00 AM, Martin Maechler
> <maechler at stat.math.ethz.ch> wrote:
>>>>>>> Michael Lawrence <lawrence.michael at gene.com>
>>>>>>> on Wed, 12 Oct 2016 15:21:13 -0700 writes:
>>
>> > Thanks, this was what I expected. There is a desire to
>>
2011 Jan 05
2
convert expressions to characters
Hi,
Suppose I have
x = parse(text = "
{y=50+50+50#'asfasf'
}
")
now x is an expression with some src attributes.
> x
expression({y=50+50+50#'asfasf'
})
attr(,"srcfile")
<text>
attr(,"wholeSrcref")
{y=50+50+50#'asfasf'
}
My question is, how can I get my string back (the string passed to
parse() as the text argument)?
>
2012 Jan 11
1
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() { #
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>