seq_along(part)) part[[i]] <- recurse(part[[i]])
> }
> part
> }
> body(fn) <- recurse(body(fn))
>
> if( !is.fun) {
> return( body( fn))
> } else {
> return( fn)
> }
> }
> #> identical( rmsrc( quote({a})), rm
for (i in seq_along(part)) part[[i]] <- recurse(part[[i]])
}
part
}
body(fn) <- recurse(body(fn))
if( !is.fun) {
return( body( fn))
} else {
return( fn)
}
}
#> identical( rmsrc( quote({a})), rmsrc( quote({a})))
#[1] TRUE
> -----Origin
Ah, I was using identical() to compare two function bodies. It returns
FALSE even when you remove srcrefs from the body:
f1 <- function(x) {
if (TRUE) { x }
}
f2 <- function(x) {
if (TRUE) { x }
}
f1b <- body(f1)
f2b <- body(f2)
attributes(f1b) <- NULL
attributes(f2b) <- NULL
# The bodies loo
>> Is this expected behavior? I can't seem to find anything in the help
>> for identical that relates to this.
>>
> It's not in ?identical, but ?Paren gives you some pointers.
> str(quote((a))) and str(quote({a})) are also informative.
Yes, looks like srcrefs are to blame:
x <- quote({ a })
y <-
Fascinating! I tried the comparisons with all.equal(), expecting a
description of the difference, but TRUE was returned in both cases.
Dave
On Wed, Oct 29, 2014 at 3:26 PM, Winston Chang
wrote:
> I ran into this and found the result very surprising:
>
> identical( quote({ a }), quote({ a }) )
On Wed, Oct 29, 2014 at 3:26 PM, Winston Chang wrote:
> I ran into this and found the result very surprising:
>
> identical( quote({ a }), quote({ a }) )
> # FALSE
>
> It seems related to curly braces. For example, parens work fine:
> identical( quote(( a )), quote(( a )) )
> # TRUE
>
> Is this