Home Comments Thread
New Thread

10 Comments

giscus-bot giscus-bot 2022-12-16 21:44:47
Guest *Josh O'Brien* @ 2012-04-06 20:45:07 originally posted:

Hi, and thanks for your tremendous work on this. When I try to view the knitr-graphics.pdf you've posted above, it fails to render and gives me the message, "There was an error processing a page. There was a problem reading this document."  (None of the other pdfs you've posted give me such an error.)

yihui yihui 2022-12-16 21:44:56

Yes I realized that a few days ago, and I have updated the Rnw source: https://github.com/yihui/knitr/commits/master/inst/examples/knitr-graphics.Rnw

Note the error occurs in Adobe Reader but not in Evince. I do not know why that is the case, but I have found out the reason to be that I used a plot containing Chinese characters, so I removed that chunk, and now if you compile the document again, everything will be fine. Anyway, I will update the PDF document later as well. Thanks a lot!

Originally posted on 2012-04-06 20:54:29

giscus-bot giscus-bot 2022-12-16 21:44:48
Guest *Rivo* @ 2012-06-11 10:46:44 originally posted:

Again an error for knitr-graphics.

Error in process_file(text) :
Quitting from lines 106-108: Error in getMetricsFromLatex(TeXMetrics) :
TeX was unable to calculate metrics for the following string
or character:

m

Common reasons for failure include:

  • The string contains a character which is special to LaTeX unless
    escaped properly, such as % or $.
  • The string makes use of LaTeX commands provided by a package and
    the tikzDevice was not told to load the package.

 

giscus-bot giscus-bot 2022-12-16 21:44:57
Guest *Rivo* @ 2012-06-11 23:15:22 originally posted:

It works .. rggobi is not available for R2.15.0 so I just commented out that part

giscus-bot giscus-bot 2022-12-16 21:44:49
Guest *Junyu Lee* @ 2012-06-27 02:20:25 originally posted:

Try to install rggobi from source, it failed. Google to check what's going on, the reason could be: it need 64 bit Windows (mine is 32 bit Win XP)

yihui yihui 2022-12-16 21:44:58

Michael Lawrence managed to build the 64bit Windows version of GGobi two weeks ago, and hopefully the Windows version of rggobi will be back on CRAN in the near future.

If you need rggobi only for this manual, you can probably remove that chunk. It was there only for demo purpose.

Originally posted on 2012-06-27 04:05:12

giscus-bot giscus-bot 2022-12-16 21:44:50
Guest *Charles Berry* @ 2012-07-04 21:51:43 originally posted:

I would like to mix LaTeX and graphics chunks in a child document and call this from a parent document chunk that loops over a variable that will generate different results in each iteration of the loop. So far, it seems like I get the same graphic produced in each loop even though the inputs ought to be different. How do I manage this?  

yihui yihui 2022-12-16 21:44:59

You can see https://gist.github.com/2475551 for an example.

Originally posted on 2012-07-04 23:20:43

giscus-bot giscus-bot 2022-12-16 21:45:00
Guest *Charles Berry* @ 2012-07-05 14:36:27 originally posted:

Thanks for the quick reply!

 I  ran the code you referenced, but no there were graphics. So I added plot(mpg~disp,df) as the last line of last chunk in template.Rnw. It ran just fine and produced 3 plots.

Then I tried pairs(df) instead of plot(). It produced 6 plots - 3 labelled  run-all[1-3].pdf and 3  gear[3-5]unnamed-chunk-2.pdf and put all of them in the document. Further, the first three looked defective - the lower right panel is missing.

yihui yihui 2022-12-16 21:45:01

The chunk 'run-all' is not supposed to have graphics output, so you need to put an extra chunk option fig.keep = 'none' to suppress the first three defective plots.

Originally posted on 2012-07-05 17:56:12

giscus-bot giscus-bot 2022-12-16 21:44:50
Guest *mrdwab* @ 2012-07-27 11:49:15 originally posted:

I really like knitr and I currently use it as follows: (1) create an R-markdown file in RStudio, (2) use "knit html", and (3) use pandoc to convert the markdown file to a PDF. For me, this is a pretty efficient workflow and generally gets me the output I expect. 

I also like the tufte LaTeX classes, which you have used in this manual.

I haven't been able to get the tufte classes to work as I expect them in this workflow though, and I'm not really sure where to seek help (you, RStudio, or pandoc). Things like marginnote do work, but they don't parse the markdown or code chunks in them. In other words, I can get a basic document without a problem, but only without the bells-and-whistles of the tufte classes.

If you can point me in the right direction or suggest an improved workflow, that would be great! I suspect that the problem might be at the pandoc level, and that solving it would require creating a new template for pandoc, but I thought I would ask here first to see if such a thing has already been done.

yihui yihui 2022-12-16 21:45:02

In fact I'm curious about the answer too, because I have also been exploring in this direction (e.g. https://github.com/yihui/thesis/blob/master/template.tex). My feeling is that you should not expect too much from the simple markdown format. Raw LaTeX is unbeatable anyway. I guess you have to either give up some fancy LaTeX features to use markdown, or just go back to LaTeX.

For me, whenever I need to write LaTeX, I use LyX. It is as good as Markdown -- easy to read and easy to write; besides, it is essentially LaTeX and the source code is surprisingly clean with unbeatable support to LaTeX math equations. I know many people really do not like it, though. The only disadvantage is you only have PDF output which does not quite fit the web. HTML export from LaTeX often does not look as clean as Markdown.

Originally posted on 2012-07-27 19:33:31

giscus-bot giscus-bot 2022-12-16 21:45:03
Guest *mrdwab* @ 2012-07-28 04:02:17 originally posted:

I do use LyX, but I really like the integration between document creation and R in RStudio, where I can directly run code from an R markdown code chunk to make sure that everything in that chunk is working as expected. I guess that since I don't use the HTML export too often, it's more of a convenience factor of not having two programs open!

I'll definitely check out your templates though.

giscus-bot giscus-bot 2022-12-16 21:44:51
Guest *Guger* @ 2012-09-21 14:11:21 originally posted:

Thank you for your excellent knitr, revolutionary package, IMHO. I have read all your manuals but still do not know how to do the following:

I need to tell knitr to insert into Latex
a line like
         includegraphics[width=linewidth]{figure/MyPlot.png}
not like
         includegraphics[width=linewidth]{figure/MyPlot}

Of course, the inserted file extension should be generated depending on device called(pdf, png, etc.)
Is there an EASY way to do that or I will have to use hooks?

yihui yihui 2022-12-16 21:45:04

At the moment there is no easy way, but it depends on your definition of "easy" -- here is one solution http://stackoverflow.com/q/11915328/559676

Originally posted on 2012-09-21 17:51:28

giscus-bot giscus-bot 2022-12-16 21:45:04
Guest *Guger* @ 2012-09-22 02:43:09 originally posted:

Thank you for your quick response!
But as far I understand the code, this change in hook behavior
works well only when I have one or two high-level plots per chunk, right?

In my case I have to generate several numbered plots in one chunk in a cycle.... I have tried fig.keep='all', 'high', but neither option resulted in more than two figures inserted.

Would you recommend to use looping approach you described at git://gist.github.com/2475551.git "use knit() with a loop to write reports for subsets of data" or I miss some simpler options here???

yihui yihui 2022-12-16 21:45:05

In theory all plots should be captured without any special tricks. I need a reproducible example.

Originally posted on 2012-09-22 05:46:38

giscus-bot giscus-bot 2022-12-16 21:45:06
Guest *Guger* @ 2012-09-22 15:30:15 originally posted:

Here is the code....
It should insert 4 identical plots (fig.keep='all') but inserts 2...
Please, give me advice if it happens due to my immaturity in
using your package which I like a lot!
 
documentclass[a4paper]{article}
usepackage[british]{babel}
usepackage{url}
usepackage{breakurl}
usepackage{graphicx}

begin{document}
title{Data Mining Project Report Template}
author{Guger}
maketitle

<>=
knit_hooks$set(plot = function(x, options) {
  x = paste(x, collapse = '.') # x is file.ext now instead of c(file, ext)
  paste0('end{kframe}', hook_plot_tex(x, options), 'begin{kframe}')
})
@

<<plot-loop, dev="pdf" ,="" fig.width="3," fig.height="2.5,out.width='linewidth'," fig.keep="all">>=
for(i in 1:4)
{boxplot(cars$dist,xlab='dist')}
@

end{document}

giscus-bot giscus-bot 2022-12-16 21:45:07
Guest *Guger* @ 2012-09-22 17:36:06 originally posted:

In my code it is a correct line, I paste it here - still correct line, when I push "Post as" - it becomes rearranged. Magic! I hope see the cycle and fix the line after copy-paste. Thanks!

yihui yihui 2022-12-16 21:45:08

Next time you can use pastebin.com or github gists. Disqus is stupid in dealing with program code; you have to escape special HTML characters manually.

For the problem in knitr, it has been explained in the graphics manual: https://github.com/downloads/yihui/knitr/knitr-graphics.pdf Basically all your plots are identical (the for loop does not make much sense), and identical plots are removed by default.

Originally posted on 2012-09-22 17:42:29

giscus-bot giscus-bot 2022-12-16 21:45:09
Guest *Guger* @ 2012-09-23 17:54:33 originally posted:

 You were right, it works, thanks! I had read the manual, I just thought fig.keep="all" keeps all of them, even identical.

yihui yihui 2022-12-16 21:45:10

Sorry I did not pay enough attention to fig.keep="all", and your understanding was absolutely correct. It should keep all four plots in theory, but I just realized that this was a feature of the evaluate package, over which I do not have control in knitr.

Anyway, I do not you will really draw identical plots in a loop in practice, so this problem probably will not bite you :)

Originally posted on 2012-09-23 18:39:29

giscus-bot giscus-bot 2022-12-16 21:44:52
Guest *Rystanley* @ 2013-01-27 01:17:31 originally posted:

Thank you so much for knitr it makes processing my reports exponentially more efficient!

I have searched forums and read the manuals but the solution to this problem has eluded me! I am still new to knitr so I apologize if this is not the best venue for my inquiry. I am generating reports where I want to report species names in my figure captions. Using the Sexpr{} option nested within the text works like a gem! However, I am wondering if it is possible to specify that the item specified in Sexpr{} be printed in italic

for example:

<<echo=false, message="FALSE">>=
SpeciesName="Gadus Morhua"
@

Figure 1. The species Sexpr{SpeciesName} are found ....

How might I have "Gadus morhua" but printed in Italics in the compiled pdf.

Thanks in advance for any advice on this issue

Cheers

yihui yihui 2022-12-16 21:45:11

You can redefine the inline hook, e.g. https://github.com/yihui/knitr-examples/blob/master/043-percent.Rnw

In your case you probably want: function(x) paste0('textit{', x, '}')

Originally posted on 2013-01-27 01:55:18

giscus-bot giscus-bot 2022-12-16 21:44:53
Guest *helmingstay* @ 2013-02-22 03:26:19 originally posted:

I'm attempting to use knitr in a manuscript in prep for plosOne, so there are lots of rules, none of them mine :)

Using dev=c('pdf','tiff') is really handy, but it looks like the dev.args list is passed to each of the devices, such that dev.args=list(compress='lzw') causes pdf() to fail from the extra arg. Have you thought of the possibility of allowing lattice-style list-of-lists for this case, ala: dev.args(tiff=list(compress='lzw'))? I tried, it didn't work. It looks my next best option is either to make a custom function for pdf() to consume the extra arg, or tiff() to pre-specify the extra arg.

I didn't find any docs on this use-case, so I figured I'd put it here, as custom devices are mentioned.

yihui yihui 2022-12-16 21:45:11

Hi, I have implemented this in the development version: https://github.com/yihui/knitr Thanks!

Originally posted on 2013-02-23 21:41:35

giscus-bot giscus-bot 2022-12-16 21:44:54
Guest *Bin Wang* @ 2013-04-20 10:36:48 originally posted:

I can't open the lyx file. It produces an error message ".....lyx is not a readable Lyx document". My lyx version is 2.0.5.1.

yihui yihui 2022-12-16 21:45:12

Do not download the web page. Download the GIT repository instead, and find the examples there: https://github.com/yihui/knitr/archive/master.zip

Originally posted on 2013-04-21 01:25:38

giscus-bot giscus-bot 2022-12-16 21:44:55
Guest *Sajni Malde* @ 2015-04-08 11:04:54 originally posted:

Thank you so much for the knitr package.

I have searched forums and read the manuals, but i cant find a solution. I have only been using knitr for 5 days now, so it might be my lack of experience.

I am currently running a for loop inside a chunk, and the code is set to plot a graph each time. The graphs are slightly different from each other. I would like to either:

save all the graphs and "print" some of them later

or:

show only certain graphs in the series. ( Not necessarily the first or last one)

I was wondering if you would be able to point me in the right direction on how to do this.

Thanks in advance for any advice on this issue

Cheers

Sign in to join the discussion

Sign in with GitHub