9 Comments
Guest *Taquiou* @ 2012-07-05 07:31:26 originally posted:
Hi,
How can I use knitr to write conditional latex output ?
I mean I have an R boolean , myboolean
if{Sexpr{myboolean}
begin{equation} ........ end{equation}
fi
See an example here: https://gist.github.com/3054020
Originally posted on 2012-07-05 14:30:55
Guest *ankit sethi* @ 2012-07-19 15:51:02 originally posted:
Hi,
I want to generate a report for three types of analysis I am performing. But each time when I perform the analysis it can happen that one or more than one type of analysis occur. I want to put condition in the report that will run the part of report according to the type of analysis performed. For each analysis I need to repeat the chunk say n times. I am stuck at writing a for loop for the code chunk.
'a' is a vector
eg:
mybooleanSexpr{myboolean}
for(i in 1:n)
section{Frequency Analysis}
<>=
print(a[i])
@
See http://tex.stackexchange.com/a/63959/9128
Originally posted on 2012-07-19 18:14:28
Guest *MartinDichter* @ 2012-07-19 09:34:10 originally posted:
I am too dumb to get it work, these demos are not helpful at all... so I'll stay with sweave, as it has rich documentation and tons of examples... and I know how to use it... and: it works!! ;)
Well, I'll appreciate it if you can point out which demos are not helpful and what is wrong with them. If you know how to use Sweave, you do not need any demos. There should not be any difficulty to switch over, because it is just a matter of calling library(knitr); knit('foo.Rnw') instead of Sweave('foo.Rnw').
Originally posted on 2012-07-19 14:26:44
Guest *knv4* @ 2012-08-13 20:39:52 originally posted:
Hi,
I'd like to create person specific reports that would loop over an i (where i is a person). Can I create that loop within knitR such that each report spits out the same format, but changes the output and graphs for the ith person?
Not sure how to go about doing this. Have any examples?
k
See:
https://github.com/yihui/knitr-examples/blob/master/020-for-loop.Rnw
https://github.com/yihui/knitr-examples/blob/master/020-for-template.rnw
Originally posted on 2012-08-14 04:41:24
Guest *knv4* @ 2012-08-16 03:04:06 originally posted:
Thanks so much for replying and for the examples. I copied the two links above, save them to .Rnw, and pressed compile.
The first one gave me the following error:
grDevices::pdf.options(useDingbats = FALSE); utils::Sweave('test.Rnw')Writing to file test.texProcessing code chunks with options ...Error in eval(expr, envir, enclos) : object 'i' not foundCalls: -> -> eval -> evalExecution halted
The second one said "knit_child" function not found.
Do you have any suggestions? Do I need do something incorrectly or need to install something for the above to work?
What should I expect as output? Several pdfs for each i?
Thank you!
You were using Sweave instead of knitr. See http://yihui.name/knitr/demo/rstudio/ on how to configure RStudio correctly.
Originally posted on 2012-08-16 05:07:15
Guest *Knv4* @ 2012-08-16 21:25:57 originally posted:
Thanks. I configured as shown. The first did not work. The second produced just one pdf. However, I was able to get this example to work: http://stackoverflow.com/questions/8434371/run-sweave-or-knitr-with-objects-from-existing-r-session/11980312#11980312
Yes you are supposed to get one PDF. If you want multiple ones, you can use the trick mentioned in the StackOverflow link.
Originally posted on 2012-08-19 01:19:44
Guest *disqus_Y56CaBrV58* @ 2012-10-05 15:01:08 originally posted:
Hi,
first of all thank you very much for the wonderful package.
I find it to be a powerful tool for reports.
I started to use it quite intensively although I encountered some problems along the way, mostly with the 'foreach' package (as I understood, not your fault BTW).
A couple of months ago I was also able to tweak a little the default highlighting scheme (that I think is the best among the built-in bright themes) to allow symbols, numbers. etc. to be coloured differently.
The problem is that a week ago I updated the package and my syntax-colour tweaks got lost and I'm not able to re-tweak the default scheme.
This is what I did so far (the same I did the last time when I was successful in modifying the theme):
- I read your discussion with Ramnath (yihui/knitr#36) about the themes you can set with 'knit_theme$set' and the eclipse theme (but I'm not really interested in them);
- I located the folder where knitr should look for .css themes files with system.file('themes', package = 'knitr');
- I modified the original default.css and tried to knit a simple .Rnw file;
- I even created the file mydefault.css, tried to look directly at it (in an interactive R session) with
opts_knit$set(out.format = 'verbatim')
knit_theme$get('mydefault')
(and the css is actually changed w.r.t. the original) and tried to set it with
thm = knit_theme$get('mydefault')
knit_theme$set(thm)
Despite all of this the result is still being produced with the default highlighting style.
It seems like knitr is able to see other css theme files (I mean, other than the default built-in ones) but not to use them.
Am I doing something wrong?
Putting a new .css file in the themes folder and using knit_theme$get('newTheme.css') and knit_theme$set shouldn't be enough?
Thank you in advance.
Federico
Hi, the syntax highlighting theme does not work very well in the latest version of knitr, and there is some work to do after R 2.15.2 is released: yihui/knitr#327 Specifically, symbols and numbers are not highlighted by default in the current version.
For the knit_theme problem, a single call like knit_theme$set('path/to/your/theme.css') should work, but again, it does not work on all kinds of symbols: only character strings, function names and comments are highlighted. That might be the source of your confusion.
Originally posted on 2012-10-05 18:08:28
Guest *disqus_Y56CaBrV58* @ 2012-10-08 09:30:05 originally posted:
Thanks for your reply.
My confusion was indeed due to the fact that I was expecting more tokens to be highlighted, as in the previous version of knitr.
Do you think is possible to use a workaround by mean of the a knit_hook that make use of the older version of the parser package (or something along these lines)?
Or do you think it's also possible to hard-code a list of symbols, number and keywords (I'm thinking about something similar to what you did for the xml file for the autocompletion of R commands in Notepad++) and makes knitr look into this file?
F.
Guest *disqus_Y56CaBrV58* @ 2012-10-08 10:57:10 originally posted:
Hi again,
probably I found something.
If I understand correctly, knitr make use of the highlighting package and its renderer_latex/renderer_html to produce the tex/html output.
I tried the first two example of the highlighting command and it seems that in the html output it is able to highlight: numbers, function names, arguments of the functions, strings and special words; whereas in the latex output is not able to highlight the special words like if else etc.
Is it this behaviour that influences knitr highlighting? Probably the fact that in the last knitr version numbers and arguments of functions are lost along the "highlighting" way is due to something going on after the call to highlight::highlight?
Thank you again,
F.
If you want the old highlighting behavior, you can set opts_knit$set(use.highlight = TRUE), but as I said, this will not be necessary after R 2.15.2 is released later this month.
Originally posted on 2012-10-08 18:07:05
Guest *David Orme* @ 2012-10-16 16:28:16 originally posted:
Hi,
I've run into a problem with being able to copy and paste code from pdfs for chunks that use the formula interface (y ~ x) . The tilde used in the latex typesetting of the code is not an ascii tilde, but an accent than has been lowered. This is defined in the file header that knitr produces:
defurltilda{kern -.15emlower .7exhbox{~{}}kern .04em}%
I think I've got a work around by changing this line to:
defurltilda{textasciitilde{}}%
But... I'm not sure if this breaks anything else! XeLatex seems to cope. Is there a better solution?
Thanks,
David
Where did you find that first definition? I cannot find it in my examples... If I do have that line in any examples, please feel free to remove or replace it. It should not break anything else.
Originally posted on 2012-10-19 05:17:28
Guest *Craig* @ 2013-03-27 03:11:03 originally posted:
Hi Yihui,
Is there any way I can pass "text" to spin or stitch functions instead of a file? I am trying to generate the report dynamically from R and I do not want to write the file to an R file and then process it using spin() or stitch().
Any suggestions?
Currently it is not possible, but that sounds like a reasonable request; please report it to https://github.com/yihui/knitr/issues so I won't forget to add this feature in the future. Thanks!
Originally posted on 2013-03-27 04:15:16
Guest *craig* @ 2013-03-27 13:38:12 originally posted:
I have added it. Thanks!
Guest *Michael Folkes* @ 2013-04-03 18:21:54 originally posted:
Hi Yihui,
Thanks for creating knitr, I think...
I'm having trouble making the pdfcrop hook work. I've sort of successfully compiled knitr-graphics.Rnw in that I do get the pdf with all plots but the cropped plot is the same as non-cropped. I'm running WinXP, R version 2.15.2 (2012-10-26). Is is possible to have a simpler demo that demonstrates just pdfcrop? Perhaps that will help with troubleshooting. I don't see any other discussions on pdfcrop other than those from 11months ago. thanks!
Please see example 085 https://github.com/yihui/knitr-examples
Originally posted on 2013-04-03 21:54:51
Guest *ShaoY* @ 2013-04-09 17:49:59 originally posted:
Hey Yihui,
Have you played with the Shiny package in R?
Is there a way to pass an input variables in Shiny's ui.R to knitR?
Please see my stackoverflow question
http://stackoverflow.com/questions/15907535/rshiny-how-to-pass-variable-from-server-r-to-an-rmd-script
I saw your question there, but I do not have time at the moment. Let's see if anyone else can answer it, or wait for one or two days till I find some time.
Originally posted on 2013-04-10 00:01:33
Guest *Wenhuo* @ 2013-11-14 16:44:42 originally posted:
When a colleague show me his document made by knitr, I was surprised and I am here now. I know Xie a long time ago from capital of statistics website and learned a lot there. Really nice work for the whole community!
Sign in to join the discussion
Sign in with GitHub