{"action":"closed","issue":{"url":"https://api.github.com/repos/yihui/knitr/issues/950","labels_url":"https://api.github.com/repos/yihui/knitr/issues/950/labels{/name}","comments_url":"https://api.github.com/repos/yihui/knitr/issues/950/comments","events_url":"https://api.github.com/repos/yihui/knitr/issues/950/events","html_url":"https://github.com/yihui/knitr/issues/950","id":56262240,"number":950,"title":"Which document is being knit?","user":{"login":"klmr","id":38931,"avatar_url":"https://avatars.githubusercontent.com/u/38931?v=3","gravatar_id":"","url":"https://api.github.com/users/klmr","html_url":"https://github.com/klmr","followers_url":"https://api.github.com/users/klmr/followers","following_url":"https://api.github.com/users/klmr/following{/other_user}","gists_url":"https://api.github.com/users/klmr/gists{/gist_id}","starred_url":"https://api.github.com/users/klmr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/klmr/subscriptions","organizations_url":"https://api.github.com/users/klmr/orgs","repos_url":"https://api.github.com/users/klmr/repos","events_url":"https://api.github.com/users/klmr/events{/privacy}","received_events_url":"https://api.github.com/users/klmr/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/yihui/knitr/labels/Feature","name":"Feature","color":"02e10c"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/yihui/knitr/milestones/22","html_url":"https://github.com/yihui/knitr/milestones/v1.10","labels_url":"https://api.github.com/repos/yihui/knitr/milestones/22/labels","id":950912,"number":22,"title":"v1.10","description":null,"creator":{"login":"yihui","id":163582,"avatar_url":"https://avatars.githubusercontent.com/u/163582?v=3","gravatar_id":"","url":"https://api.github.com/users/yihui","html_url":"https://github.com/yihui","followers_url":"https://api.github.com/users/yihui/followers","following_url":"https://api.github.com/users/yihui/following{/other_user}","gists_url":"https://api.github.com/users/yihui/gists{/gist_id}","starred_url":"https://api.github.com/users/yihui/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yihui/subscriptions","organizations_url":"https://api.github.com/users/yihui/orgs","repos_url":"https://api.github.com/users/yihui/repos","events_url":"https://api.github.com/users/yihui/events{/privacy}","received_events_url":"https://api.github.com/users/yihui/received_events","type":"User","site_admin":false},"open_issues":4,"closed_issues":37,"state":"open","created_at":"2015-01-26T08:07:29Z","updated_at":"2015-04-12T16:14:59Z","due_on":null,"closed_at":null},"comments":2,"created_at":"2015-02-02T16:58:26Z","updated_at":"2015-04-12T16:14:59Z","closed_at":"2015-04-12T16:14:59Z","body":"This is related to #564: My code needs to find out whether it’s being called from inside a knitr document. However, in addition to that, it needs to find out *which* document is being knit, i.e. the full path to that document.\r\n\r\nThe background for this is klmr/modules#31: *modules* needs to know the base path of its calling code in order to resolve relative import file locations. At the moment, it resolves to the directory of the code which kicks off the knitting process, which is usually not the correct directory.\r\n\r\nInside *modules* I cannot fix this issue without requiring the user to manually specify the module base path, which I’d like to avoid.\r\n\r\n## MWE:\r\n\r\n* **`doc.rmd`**:\r\n\r\n        ```{r}\r\n        devtools::install_github('klmr/modules')\r\n        modules::import('./test')\r\n        ```\r\n\r\n* **`test.r`**:\r\n\r\n    ```r\r\n    message('I was called correctly.\\n')\r\n    ```\r\n\r\n* **`script/knit`**:\r\n\r\n    ```r\r\n    #!/usr/bin/env Rscript\r\n    knitr::knit('doc.rmd', 'doc.md')\r\n    ```\r\n\r\n```bash\r\nchmod +x script/knit\r\n./script/knit\r\n```\r\n\r\n### Expected output:\r\n\r\n> […]  \r\n> \\#\\# I was called correctly!\r\n\r\n### Actual output:\r\n\r\n> […]  \r\n> \\#\\# Error in `modules::import(\"./test\")`: Unable to load module `./test`; not found in `\"./script\"`"}}