Super. So do you just prefix any options the device expects with
"fig.", e.g. can you specify fig.ps=13 to change the pointsize for
pdf?
I've enhanced the default knitr plot hook to automatically generate
\begin and \end{figure} if you specify for example <<chunkname,
caption=some caption>>. You don't need fig=TRUE at any rate. I could
not figure out how to get knitr to allow a comma in the caption - it
doesn't allow caption=". . ." or {. . .} or "<. . .>". Unless someone
has a better idea I'll intercept ;; inside caption= and change it to a
comma, inside the hook.
Frank
On Feb 8, 12:07 pm, Carl Boettiger <cboet...@gmail.com> wrote:
> You can set the R device options globally (in \SweaveOpts) or for any
> chunk. e.g. for your example:
>
> \begin{figure}
> <<fig=TRUE, dev=pdf, fig.width=4, fig.heigth=3>>=
> plot(...)
> @
> \end{figure}
>
> On Wed, Feb 8, 2012 at 10:01 AM, Frank <harre...@gmail.com> wrote:
> > I frequently produce graphics whose size I control using for example
> > pdf(..., width=4, height=3) (sizes are in inches). I see from knitr
> > documentation how to tell LaTeX what size to use for \includegraphics,
> > but how do we pass through other arguments to the graphics device
> > (e.g;., pdf()) that knitr automatically calls?
> > Thanks
> > Frank Harrell
>
> --
> Carl Boettiger
> UC Davishttp://www.carlboettiger.info/
my_pdf = function(file, width, height) {
pdf(file, width = width, height = height, pointsize =
opts_current$get('pointsize'))
}
The object opts_current gives you the chunk options for the current
chunk, so you can use any custom options in your hooks or device
functions, e.g.
<<pdf-with-pointsize, dev=my_pdf, width=5, height=4, pointsize=10>>=
plot(1)
@
For the caption problem, I have been thinking on how to deal with
commas as well. You can use other characters to replace commas when
writing the captions, and replace them back to commas in the hook to
get the real captions. For example, use ;; as , and I guess a neater
solution is to be able to escape the comma like \,. I will see what I
can do.
Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA
In fact you may not need to evaluate 'name' in @name; there is an
alternative way to do that. You can set
opts_knit$set(eval.opts = c('eval', 'echo', 'caption')) # see
http://yihui.name/knitr/options#package_options
then use
<<>>=
.fig.caption = 'a long long caption here'
<<my-caption, caption=.fig.caption>>=
@
In this case, the caption will be evaluated to the real character string.
Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA
Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA
Or alternatively, you can use the argument 'options' in the hook
function; it is always the evaluated version.
knit_hooks$set(caption = function(before, options, envir) {
if (!before) paste('\\caption{', options$caption, '}')
})
Theoretically 'options' in the hook function should be identical to
opts_current$get(), but due to that bug, they are not. The fix will
appear in v0.3 on CRAN about two weeks later.
Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA
An alternative way to install the beta version is to download the tar
ball and run R CMD INSTALL:
https://github.com/yihui/knitr/tarball/master Perhaps this is not
clear enough in https://github.com/yihui/knitr#readme
'A B' is not a legal R expression, so parse() cannot parse it; I'm not
sure if this should be considered as a bug, because 'eval.opts' means
the option will be evaluated like an R expression. What do you expect
knitr to behave in this case?
Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA
Commas will be allowed soon but they have to be escaped. I'm working
on it: https://github.com/yihui/knitr/issues/128
Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA
It is entirely possible to implement your idea (use commas in quoted
strings), but I'd like to keep the syntax consistent -- whenever a
comma has its literal meaning, it must be escaped. Otherwise we have
to remember when to escape it and when not to.
I hope this is an acceptable solution.
Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA
It would be consistent with R syntax to evaluate "naked" identifiers,
and require strings to be quoted. But that's probably too invasive a
change to knitr at this point.