-
-
Notifications
You must be signed in to change notification settings - Fork 878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Which document is being knit? #950
Comments
I don't fully understand the modules package, but when you are in knitr code chunks, the working directory is the directory that contains the input document by default. See the Note section in |
Apologies, I should have described this better: Unfortunately the working directory doesn’t help me — in fact, modules intentionally does not use the working directory since that is generally completely arbitrary and has no relation to the file being executed. Instead, modules detects whether the code was launched via In the MWE given above, this would be If it helps, consider another example with the following file structure (similar to one I’m actually using):
The results/%.html: analysis/%.rmd
bin/knit $< $@ Here, my working directory would always be |
Got you. I think |
Thanks, this looks almost perfect, there’s just one issue: After a call to on.exit(knit_concord$set(infile = NULL, outfile = NULL), add = TRUE) |
I have got it early on there: https://github.com/yihui/knitr/blob/8e2910e09/R/output.R#L132 Just pushed a fix to check if |
👍 Thanks a lot. |
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary. |
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.
The 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.
Inside modules I cannot fix this issue without requiring the user to manually specify the module base path, which I’d like to avoid.
MWE:
doc.rmd
:test.r
:message('I was called correctly.\n')
script/knit
:Expected output:
Actual output:
The text was updated successfully, but these errors were encountered: