4 Comments
Guest *Sepehr Akhavan* @ 2012-07-04 19:04:40 originally posted:
Hi Yihui,
Would you be able to explain your first hook example? Here is your code:
<<par-hook, cache="FALSE">>=
knit_hooks$set(pars = function(before, options, envir)) {
if (before) graphics::par(options$pars)
}
@
<<use-pars, pars="list(mar=c(4," 4,="" .1,="" .1),="" mgp="c(2," 1,="" 0))="">>=
plot(mtcars[, 1:2])
@
- I don't understand the graphics::par(options$par) part. Do we an object called options? what does :: do?
- I have another challenge and that is passing a list to pars in the code chunk. I remember from your hooks page that the options calling hooks should only get logical values, but here we are passing a list to the hook function.
Perhaps my question is a silly question to you, but without doubt, your answer can help me a lot.Best,-Sepehr
-
You do not have to use :: -- I was using it for the sake of rigor. a::b means to use the function b in the package a. This is to prevent name clashes, e.g. the user created another function named par() which could mask the par() in the graphics package. See ?'::' for details.
-
That is an old impression. You have a good memory! :) Now the chunk hook is called whenever the chunk option is not NULL; see http://yihui.name/knitr/hooks Because a list is not NULL, the pars hook will be called.
Originally posted on 2012-07-04 20:57:19
Guest *Sepehr Akhavan* @ 2012-07-04 21:48:30 originally posted:
Very helpful.
Thanks :)
-Sepehr
Guest *Ulrich Bodenhofer* @ 2013-05-17 08:18:40 originally posted:
I understand and appreciate knitr's policy to format large numbers in scientific notation. However, I have encountered that this happens even if I intensionally use format() to enforce a particular format. knitr seems to override this and I really wonder how this is possible, as both format() returns a character string, right?. Are there any options of format that are globally altered by knitr? Any help is gratefully appreciated!
Let's discuss this on StackOverflow: http://stackoverflow.com/q/16604652/559676
Originally posted on 2013-05-23 04:18:10
Guest *catfish* @ 2013-06-10 09:57:23 originally posted:
Maybe something wrong in the following code:
<<par-hook, cache="FALSE">>=
knit_hooks$set(pars = function(before, options, envir)) {
if (before) graphics::par(options$pars)
}
@
should be
<<par-hook, cache="FALSE">>=
knit_hooks$set(pars = function(before, options, envir) {
if (before) graphics::par(options$pars)
})
@
thanks; fixed now
Originally posted on 2013-07-11 05:50:35
Guest *Mario Menezes* @ 2016-02-25 14:08:51 originally posted:
Hi,
The only thing that prevents me from abandoning Sweave is the lack of control on chunck font sizes in Beamer presentations. No matter what options I try, chunck results are always the same size (default Beamer size).
This is not optimal, since some times the output is slightly bigger than the slide and having the option to lower a little bit the font size would be very important for me.
Is there a way to do this in R Markdown, without resorting to Sweave
Regards.
I'm not sure. Probably wrapping the chunk in something like scriptsize{ }?
Originally posted on 2016-02-26 21:03:24
Guest *Mario Menezes* @ 2016-02-27 14:54:18 originally posted:
Hi Yihui,
Tks for your reply. In fact, using scriptsize{} didn't work, because LaTeX gets confused when processing the resulting .tex file. Maybe some extra } is left by knitr.
But using your tip, I tried other ways of using this simple idea.
The combination that worked is:
scriptsize
# R code here
normalsize
Without the normalsize after the chunk, LaTeX will continue to put everything in that environment (frame) in scriptsize fonts.
Thanks for your attention.
Best regards
Mario
Sign in to join the discussion
Sign in with GitHub