{"action":"opened","issue":{"url":"https://api.github.com/repos/rdpeng/ProgrammingAssignment2/issues/1652","repository_url":"https://api.github.com/repos/rdpeng/ProgrammingAssignment2","labels_url":"https://api.github.com/repos/rdpeng/ProgrammingAssignment2/issues/1652/labels{/name}","comments_url":"https://api.github.com/repos/rdpeng/ProgrammingAssignment2/issues/1652/comments","events_url":"https://api.github.com/repos/rdpeng/ProgrammingAssignment2/issues/1652/events","html_url":"https://github.com/rdpeng/ProgrammingAssignment2/issues/1652","id":131677303,"number":1652,"title":"Example is flawed: additional parameters are not checked.","user":{"login":"reitzig","id":4246780,"avatar_url":"https://avatars.githubusercontent.com/u/4246780?v=3","gravatar_id":"","url":"https://api.github.com/users/reitzig","html_url":"https://github.com/reitzig","followers_url":"https://api.github.com/users/reitzig/followers","following_url":"https://api.github.com/users/reitzig/following{/other_user}","gists_url":"https://api.github.com/users/reitzig/gists{/gist_id}","starred_url":"https://api.github.com/users/reitzig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reitzig/subscriptions","organizations_url":"https://api.github.com/users/reitzig/orgs","repos_url":"https://api.github.com/users/reitzig/repos","events_url":"https://api.github.com/users/reitzig/events{/privacy}","received_events_url":"https://api.github.com/users/reitzig/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-02-05T15:50:51Z","updated_at":"2016-02-05T15:50:51Z","closed_at":null,"body":"The example implementation is (deeply?) flawed: `cachemean` allows passing through additional parameters to `mean`, but successive calls may have different parameters. Since the values are not checked for, the mean cached after the first call is returned even though it's (arguably) wrong:\r\n\r\n```R\r\n> x <- makeVector(c(1:100,200))\r\n> cachemean(x)\r\n[1] 51.9802\r\n> cachemean(x, trim=0.1)\r\ngetting cached data\r\n[1] 51.9802\r\n> mean(x$get(), trim=0.1)\r\n[1] 51\r\n```\r\n\r\nSimilar examples can be constructed with the `na.rm` parameter of `mean`.\r\n\r\n*Proposed solution:* Drop the `...` parameter from `cachedmean`.\r\n\r\n(That is, if it is possible to check the parameters and/or cache one value per parameter combination, that may be a good solution as well. But 1) that's probably beyond the course at this point and 2) it may be a recipe for memory leaks.)"}}