-
-
Notifications
You must be signed in to change notification settings - Fork 873
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
selectively include output of a chunk? #108
Comments
You may read the main manual again to know the six types of output from a chunk (section 2: https://github.com/downloads/yihui/knitr/knitr-manual.pdf). They are orthogonal to each other, meaning that you can turn on/off each piece without worrying about other pieces. In your case, you can use For the second problem, at the moment you have to split the code into 4 chunks and use the ugly settings, but this issue has given me an inspiration: currently we can choose which plot to show in a chunk using |
I would support this feature. One immediate application I can see is for blogs. I like to explain my code in steps, but want to provide a single downloadable file. Having an option like |
thanks for the 1. foo = lapply(1:10, function(x) {
2. print(x)
3. }) using echo=1:2, referring to the line numbers in the initial source file where it encompassed the full expression, might mean that after tidying, say, one also has to include line 3. One safe option here might be to include syntactically complete expressions. |
Good point; |
This feature has been implemented. See |
That's great, thanks a lot! |
The difficulty is that <<echo=show_lines>>=
3
2
5
@ |
Oh, I see. That's unfortunate. If you're going to introduce a non-standard notation, I'd suggest not mixing it with pseudo-R code like
or
|
Before I make this option powerful, I think it is often enough with |
When I use |
I did this on purpose. When the source code is removed, its following output is also removed. I was mainly thinking about text output like this: 1 + 1
## [1] 2 I thought it could be weird if the reader saw the output without the corresponding source code. But you seem to be right -- plots may need to be treated differently. |
i see, and yes, it would be very useful to keep the plots. Thanks! |
it is fixed in the devel version 0.2.5 |
thanks! |
Would it be possible to mark not only the beginning of a chunk in an external file but also it end? I often have an .R file in which I try out a whole bunch of different things, few of which I would ever want in the final document. If, instead of just being able to declare
but also have something like
(no idea if that's the ideal syntax) I could easily isolate those parts of the script I actually want to appear in the document without having to keep track of the number of expressions in the chunk that I then have to pass to |
The beginning of the next chunk is the end of the previous chunk, so you can just start another chunk, e.g.
|
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. |
Hi,
I've been using the very handy externalization feature of
knitr
, where I can conveniently develop the R code, and when it's polished insert the relevant bits inside a Rnw document. A common problem I face is the following: say my analysis is split into a few steps,1- (lengthy / messy) definition of some functions [ don't show in final report ]
2- call to the function [ show in final report ]
3- (messy / lengthy) creation of the plot using ggplot2 [ don't show in final report ]
4- printing the plot [ only show the plot in the final report, not the
print(p)
statement ]In the final report, I often find I don't want to overwhelm the reader (me, in fact) with technical details such as (1) and (3). In the current workflow, this means that I'll have to split this into 4 chunks, even though it's really the same part of the study. Further, I need to worry about setting echo=T/F, include=T/F, dependson= for each of these 4 chunks.
I wonder if this could be simplified somehow, by allowing one of two things:
The text was updated successfully, but these errors were encountered: