Bug 17124 - addmargins() fails if supplied functions are not defined in the stats namespace or parent environment thereof
Summary: addmargins() fails if supplied functions are not defined in the stats namespa...
Status: UNCONFIRMED
Alias: None
Product: R
Classification: Unclassified
Component: Models (show other bugs)
Version: R-devel (trunk)
Hardware: All All
: P5 minor
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2016-07-27 09:19 UTC by Alex Bertram
Modified: 2016-08-16 12:04 UTC (History)
1 user (show)

See Also:


Attachments
Patch for addmargins against r70990 (1.22 KB, patch)
2016-07-27 09:19 UTC, Alex Bertram
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Bertram 2016-07-27 09:19:55 UTC
Created attachment 2134 [details]
Patch for addmargins against r70990

An example from the addmargins help page fails if evaluated in a local environment:


local({
    
    mB <- structure(c(16, 26, 27, 20, 24, 20, 19, 25, 40, 46, 46, 45), 
    .Dim = c(4L,  3L), 
    .Dimnames = list(Sea = c("Black", "Dead", "Red",  "White"), 
                     Bee = c("Buzz", "Hum", "Total")), 
    class = c("table", "matrix"))
    
    sqsm <- function(x) sum(x)^2/100

    addmargins(mB, 1, list(list(All = sum, N = sqsm)))

})

A test and fix is attached.