-
-
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
Specify working directory #162
Comments
Thanks for the suggestion! I agree I should make the input/output more flexible and should not tie them to physical files. I will see what I can do about this. |
That would be great! Right now my workaround is to create the temporary files in the working directory I want to use which isn't ideal as it clutters up the directory. Thanks for looking into this! |
Now it supports library(knitr)
pat_html() # patterns for reading input
knit(stdin(), stdout())
this is a markdown example in stdin():
<!--begin.rcode setup, include=FALSE
render_markdown() # setup output hooks
## can also try render_gfm()
end.rcode-->
try some code:
<!--begin.rcode hello
1+1
rnorm(5)
end.rcode-->
OK, time to press Ctrl+D now. |
Another important use-case is people writing scripts. Example: I'm building a website with I had great difficulty getting your code to work. A few tips:
I'm adding this here for posterity in case anyone comes here by googling "knitr stdin" (as I did), hoping to turn knitr into a text filter. |
Thanks for the exploration! I think the error message about The primary use of knitr is through files, and I do not quite encourage you to rely on stdout in R, because it is very easy to "pollute" it through a careless |
I agree it's easy to do that, but I think it's probably OK for a standalone script which I can maintain and reuse many times. BTW, I was using |
Yes, you wrote So the solution is |
Total facepalm. Rookie mistake. I can't believe I used the double quotes. Thanks for pointing that out -- that had been bugging me! |
That is fine. I have been bitten by |
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. |
I have an R script that reads a source markdown from stdin, saves it to a temporary file (in
/tmp
), runs it through knitr, and then writes the processed file to stdout. This lets me get a live preview of my R computations in Marked.app on the mac.I used to set the input.dir option before calling knit to change the working directory in which knit processes the R code. This way I could keep data references relative to my source document. With version 0.3.0 input.dir looks like it's always set to the directory of the input file. This doesn't work in my case where the input and output file are temporary files.
Would it be possible to check first if input.dir is set and only change it if it's not? The other option is to have a separate option for specifying the working directory.
The text was updated successfully, but these errors were encountered: