Plots and Command Output?

54 views
Skip to first unread message

Derek Ogle

unread,
Jul 4, 2012, 2:17:08 PM7/4/12
to kn...@googlegroups.com

knitr’s,

 

I would like to have a chunk that echos all R commands, shows the results that would be printed to the console below the R commands, but “saves” the graphs to be used in an \includegraphics call and does not print the graphs immediately after the R command that constructs the graph.  I can’t seem to find the right combination of include=, results=, echo=, etc. that will result in what I want.  I guess my question is … is it possible to suppress the immediate showing of graphics while still allowing the immediate showing of R console output within the same chunk?

 

In the attached example, I would like the results from chunk 3 with the exception that the histogram immediately following hist() (the unlabeled histogram) would not appear.

 

Any thoughts on how to accomplish this task would be greatly appreciated.  Thank you in advance.

 

Dr. Derek H. Ogle

Professor of Mathematical Sciences & Natural Resources

Northland College

1411 Ellis Ave

Ashland, WI  54806

 

e-mail: do...@northland.edu

web: www.ncfaculty.net/dogle/

 

junk.Rnw
junk.pdf

Carl Boettiger

unread,
Jul 4, 2012, 2:22:25 PM7/4/12
to Derek Ogle, kn...@googlegroups.com
If you'd like the figures not to appear in the resulting pdf at all, I think you'll want to redefine plot at the beginning of your script:

    knit_hooks$set(plot = function(x, options) "") 

e.g. I add this command before calling knit() when I want to compile a pdf where images are not embedded (e.g. for journals that require this).  Could probably be set chunk by chunk if necessary, but I'm guessing you want this to be the global behavior.  

hth,

Carl
--
Carl Boettiger
UC Davis
http://www.carlboettiger.info/

Yihui Xie

unread,
Jul 4, 2012, 2:45:07 PM7/4/12
to Carl Boettiger, Derek Ogle, kn...@googlegroups.com
Wow, that is a smart trick. Thanks, Carl!

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

Derek Ogle

unread,
Jul 4, 2012, 6:16:20 PM7/4/12
to Carl Boettiger, kn...@googlegroups.com

Carl,

 

That does the trick!!  Thanks for the very prompt help (I never would have come up with that).

Reply all
Reply to author
Forward
0 new messages