Bug 17339 - `body<-` does not preserve attributes
Summary: `body<-` does not preserve attributes
Alias: None
Product: R
Classification: Unclassified
Component: Language (show other bugs)
Version: R 3.3.*
Hardware: All Linux
: P5 normal
Assignee: R-core
Depends on:
Reported: 2017-09-12 18:40 UTC by Neal Fultz
Modified: 2017-09-12 18:40 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Neal Fultz 2017-09-12 18:40:03 UTC
`body<-` appears to not preserve attributes set on functions. Sometimes I use attributes on functions, eg for memoization, etc. Here is a small test case:

> f <- structure(function(x) x+1, foo='bar')
> attributes(f)
function(x) x+1

[1] "bar"

> body(f) <- body(mean)
> attributes(f)

I would expect changing the body to not affect the attributes at all.