{"action":"opened","issue":{"url":"https://api.github.com/repos/yihui/knitr/issues/1141","labels_url":"https://api.github.com/repos/yihui/knitr/issues/1141/labels{/name}","comments_url":"https://api.github.com/repos/yihui/knitr/issues/1141/comments","events_url":"https://api.github.com/repos/yihui/knitr/issues/1141/events","html_url":"https://github.com/yihui/knitr/issues/1141","id":122246253,"number":1141,"title":"automatically add appropriate cache.extra for source() etc commands in chunks","user":{"login":"maxheld83","id":5372770,"avatar_url":"https://avatars.githubusercontent.com/u/5372770?v=3","gravatar_id":"","url":"https://api.github.com/users/maxheld83","html_url":"https://github.com/maxheld83","followers_url":"https://api.github.com/users/maxheld83/followers","following_url":"https://api.github.com/users/maxheld83/following{/other_user}","gists_url":"https://api.github.com/users/maxheld83/gists{/gist_id}","starred_url":"https://api.github.com/users/maxheld83/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maxheld83/subscriptions","organizations_url":"https://api.github.com/users/maxheld83/orgs","repos_url":"https://api.github.com/users/maxheld83/repos","events_url":"https://api.github.com/users/maxheld83/events{/privacy}","received_events_url":"https://api.github.com/users/maxheld83/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-12-15T10:57:19Z","updated_at":"2015-12-15T10:57:19Z","closed_at":null,"body":"I often `source()` quite computationally expensive scripts within an `*.Rnw`, and I a) would like therefore to have these results cached, and b) have it *automatically* rebuild the cache if something changes in the `source()`ed script.\r\n\r\nI imagine this is a relatively common scenario, and a \"gotcha\"-aspect of knitr caching: it's easy to forget that while a chunk is re-cached if its string content changes, it *will not be re-cached* if some downstream, sourced script changes (makes sense, of course).\r\n\r\nI've now solved this like so:\r\n\r\n```\r\n<<simulations, cache.extra = tools::md5sum(\"R/simulations.R\")>>=\r\n# this also caches again whenever the content of R/simulations.R has changed\r\nsource(\"R/simulations.R\")\r\n@\r\n```\r\n\r\nso, whenever I source a script, I also add a `cache.extra` to that effect.\r\n\r\nWould it be feasible/desirable to add this kind of functionality as a default option, whenever a `source()` etc. are used?\r\nOr does this just create more headaches for everyone?"}}