-
-
Notifications
You must be signed in to change notification settings - Fork 879
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
Commented out Sexpr #110
Comments
It is easy to solve -- just destroy |
Sure, that's what I'm used to doing... and that's the part that bugs me ;-)
|
You mean comment all of them out using a global option? Why? That is going to make many incomplete sentences. |
I mean that Sexpr in commented latex text should not be run. When you comment out a chunk you usually also comment out the surrounding latex. The chunk is not run (thus some variables are not created) but the Sexpr is still run (and references to the variables fail...) |
I see. That is difficult, because it conflicts with the design of inline R code, which means code is in text lines (no matter what kind of lines) instead of individual blocks. If you comment out a block, the block is gone, but if you comment out texts with inline code, the code is still inline. I do not have a trick for this issue, so I cannot do much about it at the moment. |
What about changing the inline.code pattern to something like: |
This sounds like a good direction to go, but is not directly applicable to |
The difficulty is you have two library(stringr)
str_locate_all("abc \\Sexpr{1}", "^[^%]*\\\\Sexpr\\{([^\\}]*)\\}")
## [[1]]
## start end
## [1,] 1 13
## So I do not plan to add this feature. One way to get around is to use child documents, which you can easily comment out as a block: http://yihui.github.com/knitr/demo/child/ |
Sure, but this all applies to the child document all over again. Unless you're saying put every piece of code in it's own child Rnw, this doesn't help. Honestly, this is a big deal. It violates all expectations about the meaning of "comment out". I really don't understand the problem, especially since it already works that way for <<>>=@ code chunks. I had darn well better be able to do use something to easily comment out a section of a Rnw file and know that it is both not going to be executed in R and not be processed by latex. Commenting out in latex and mangling the command is not acceptable to me. FYI, this also leads to bugs processing things like the preamble that are commented out since comments are ignored. |
that makes sense, and I'm looking forward to your pull request :) |
Would this work (of course, this is currently latex specific and would not work for languages with multiline comments...)? locate_inline = function(input, pattern) {
input = gsub("(^|\n|[^\\\\])(%[^\n]*)", "\\1\\U\\2", input, perl=TRUE)
x = cbind(start = numeric(0), end = numeric(0))
if (group_pattern(pattern))
x = str_locate_all(input, pattern)[[1]]
x
} |
you are right -- multiline comments will be tricky I think I'd like to add support to LaTeX at the moment |
Argg... this will also fail if you have 2 Sexpr on the same line and a % sign in the first one :-( |
Is it acceptable that I just ignore the lines |
I think that would be good enough for me. But that's just me ;-) |
For me, it makes little sense to read the tex document; to read the source, use Rnw; to read output, use PDF. The intermediate tex file is often messy, so probably people will not yell at me if I just remove the LaTeX comments in Rnw. |
Never underestimate the capability of people to yell at you ;-) |
then it will be inconvenient for those who want to comment out Sexpr -- they have to set the option before OK, let me do it this way: I just remove inline R code from LaTeX comments, e.g. |
Actually, you could just remove the \ sign so that your regex won't match but there is a minimal loss of information... |
OK, as a compromise, |
Deal ;-) |
inline comments will be stripped off; this only happens to LaTeX currently
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. |
Something that always bugged me with Sweave is the fact that Sexpr are evaluated even though the corresponding latex code is commented-out.
Unfortunately it still bugs me in knitr ;-)
Any chance you could fix that?
Thanks.
The text was updated successfully, but these errors were encountered: