Home Comments Thread
New Thread

19 Comments

giscus-bot giscus-bot 2022-12-16 21:45:26
Guest *idrisr* @ 2012-04-09 04:54:06 originally posted:

I'm struggling to see how to create a  .markdown file and convert it to html? Point me in the right direction?

yihui yihui 2022-12-16 22:16:42

I'm still working on the conversion, and this is not likely to happen very soon, but we are actually very close to it. I just want to leave some work to my Google Summer of Code project, so I'm intentionally slow...

For now, you can use pandoc for conversion, or just rely on GitHub as my example above shows. Hopefully in the next few weeks you will start seeing native support at least in RStudio for HTML conversion.

Originally posted on 2012-04-09 05:10:57

giscus-bot giscus-bot 2022-12-16 21:45:27
Guest *Rich* @ 2012-05-06 01:16:54 originally posted:

Your comments about not breaking other languages are interesting!  Do you think you will extend this thinking to a file format where R is the protected format?  What I mean is that all the documentation is in comments, and the file remains valid R code if you were to copy it in.  

Something like

My analysis## ===========#### Text describing the analysisset.seed(1121)(x <- rnorm(20))

giscus-bot giscus-bot 2022-12-16 22:16:43
Guest *Rich* @ 2012-05-06 01:18:00 originally posted:

Oh dear, the formatting got lost, but perhaps you get the idea. :)

yihui yihui 2022-12-16 22:16:44

Thanks for the suggestion! Yes I understand your idea, and I did think about it. The reason I did not really do it was that I did not see much gain in doing so. I mean although the document becomes a valid R script (documentation is commented out), the compilation is nearly the same. If you want to generate a report based on an R script, you may consider the function stitch() in knitr: http://yihui.name/knitr/demo/stitch/

Originally posted on 2012-05-06 01:59:43

giscus-bot giscus-bot 2022-12-16 21:45:28
Guest *Remko Duursma* @ 2012-05-08 02:28:13 originally posted:

Excellent package. 
I ran the knitr-minimal.Rnw example, and noticed that in your pdf output (knitr-minimal.pdf), the figures are placed inside the grey code box, but in my pdf output they are not (they are placed below). I also noticed on your websites some examples of both.

What is the problem you think? (I have the newest version of knitr, as well as highlight, and R).

yihui yihui 2022-12-16 22:16:45

Hi, my own PDF output is not updated, and the background of the plots are supposed to be white. You are encouraged to run knitr and generate the PDF's by yourself since all the source documents are there. Sorry about the confusion.

Originally posted on 2012-05-08 03:27:44

giscus-bot giscus-bot 2022-12-16 21:45:29
Guest *Remko Duursma* @ 2012-05-08 02:34:25 originally posted:

And I just noticed that when I include a figure produced by rgl (with rgl=TRUE, and the rgl hook), it does place the figure in the grey code box.

yihui yihui 2022-12-16 22:16:46

rgl plots are different with normal R plots because they are not recordable by recordPlot() (see the knitr graphics manual), so the rgl plots are treated like text output and share the gray background.

Originally posted on 2012-05-08 03:29:17

giscus-bot giscus-bot 2022-12-16 21:45:30
Guest *datapixie* @ 2012-06-26 19:48:38 originally posted:

The knitr-minimal.Rnw example doesn't work for me from inside RStudio when I click on "Compile PDF". If I add the line "library(knitr)" inside the first code block, then at least it will compile, but then the pictures do not show up, and the displayed code does not have syntax coloring.

If I do knit("knitr-minimal.Rnw"), and then LaTex the resulting file elsewhere, it becomes clear that I have to add the line "usepackage{alltt}" to the .Rnw file. Once I do that, then LaTexing elsewhere produces the proper PDF. But even after this change, I still get no pictures from the "Compile PDF" button in RStudio.

Sorry if this is an RStudio question and not a knitr question... but I'll be really happy if I can get this all to work within RStudio.

yihui yihui 2022-12-16 22:16:46

Sorry the alltt problem is a known bug, which I have fixed in the development version on Github: https://github.com/yihui/knitr#readme

The RStudio problem looks like you did not configure it properly so RStudio was actually using Sweave (default) instead of knitr: http://yihui.name/knitr/demo/rstudio/

Originally posted on 2012-06-27 00:26:57

giscus-bot giscus-bot 2022-12-16 22:16:47
Guest *datapixie* @ 2012-06-27 01:42:43 originally posted:

awesome, thanks!

giscus-bot giscus-bot 2022-12-16 21:45:30
Guest *AJ Rossini* @ 2012-10-25 13:00:12 originally posted:

actually, you got it a bit wrong.  The original noweb syntax (thanks to Norman Ramsey) was to have code chunks and doc chunks interspersed, with means to have code chunks in other code chunks, but left the doc chunks unlabelled.  From this, you could use any doc language(but needed to be consistent, no facility for switching)  and any code language (which could be inconsistent, since there was a facility for switching and annotation.  You should read Norman's tech report (and I think he had a publication that is citable) for that.
Sweave broke the noweb syntax by mixing up code in the doc chunks, but this wasn't a bad idea in theory, since Fritz wanted to do reporting.  
If I had started with nuweb (which was a cleaner but trickier code-language agnostic language), we'd have made a bit more progress..

best,
-tony

yihui yihui 2022-12-16 22:16:48

Thanks so much, Tony. I'm excited to see an expert in this area like you here.

I remember I read the two articles on Norman Ramsey's website when I started re-inventing the wheel last year: http://www.cs.tufts.edu/~nr/noweb/ (is there another report I missed?) I do not quite understand your comments about noweb, or perhaps I did not make myself clear enough. I do not actually have much complaint about the noweb syntax; I mean I would have used something like % chunk.begin and % chunk.end instead of <<>>= and @, but that is more like a personal taste instead of a really big problem.

What I do not like are SweaveOpts{} and SweaveInput{}. They could have been avoided by properly using code chunks (in knitr, I use opts_chunk$set() to set global chunk options, and <<child='file.Rnw'>> to include child documents). Pseudo LaTeX commands bring additional parsing difficulties for developers, and require additional memory of users to remember new LaTeX commands (and since they look like LaTeX commands, they can be odd to appear in a literate programming document in HTML or other doc formats).

Thanks for pointing out nuweb. I saw that just a few days ago, and initially I thought it was a typo of noweb :-) I just glanced at its user manual, and it seems to be huge improvement over noweb. I'm wondering if we start with nuweb, how far are we from products like these reports? http://www.rpubs.com

Originally posted on 2012-10-25 18:40:17

giscus-bot giscus-bot 2022-12-16 21:45:31
Guest *Bastiaan Quast* @ 2012-10-27 11:53:52 originally posted:

Thank you very much for this, I tried to replicate your minimal.Rmd example and upload it to Github, but the pictures won't display. I guess this is because they are in the figure folder, is there a way to avoid this?

yihui yihui 2022-12-16 22:16:49

It is tricky if you do not understand how Github handles the content in the repositories. For images, you have to use their raw URL's. For example, the raw link of this image https://github.com/yihui/knitr/blob/master/inst/examples/md-cars-scatter.png is https://raw.github.com/yihui/knitr/master/inst/examples/md-cars-scatter.png or https://github.com/yihui/knitr/blob/master/inst/examples/md-cars-scatter.png?raw=true You have to let knitr know this change in the URL (the default direct link will not work). For beginners, here is a simple solution: http://yihui.name/knitr/demo/upload/ Once you know Github well enough, you can set the root.url option: http://yihui.name/knitr/options (e.g. https://github.com/yihui/knitr/blob/master/inst/examples/knit-all.R#L24).

The other even easier approach is to use RStudio and RPubs.com.

Originally posted on 2012-10-27 19:44:11

giscus-bot giscus-bot 2022-12-16 21:45:32
Guest *Marcus R* @ 2013-02-01 18:50:54 originally posted:

Hi. I am about to write my masters thesis. I am right now setting up my software environment with git, R, latex etc within a Ubuntu 12.04 installation. I used Sweave for my Bachelors thesis but I will now give knitr a try. But I have some problems.

I decided to first try try replicate the 002-minimal.Rnw above with the commands:
Rscript -e "library(knitr); knit('002-minimal.Rnw')"
pdflatex 002-minimal.Rnw.tex

But then I get a error that says:
! Undefined control sequence.
l.59 SweaveOpts
{concordance=TRUE}

And in the resulting pdf there is this text above that says:
concordance=TRUE

I know you have a guide for R Studio to output PDF (even though I still have trouble with it). But do you have, or know about, some guide that how to use command line to get a good PDF-output. I know there are pdfLatex, knit2pdf and a lot of different programs but there is so much to get into.

And also, I almost forgot, thanks a a lot for this package, when I get hold of it it really going to turn my thesis studies from frustration to Euphoria! :)

yihui yihui 2022-12-16 22:16:50

Delete that line: SweaveOpts{concordance=TRUE} (it is useless for knitr) Note I do not have that line in my 002-minimal.Rnw example.

Originally posted on 2013-02-02 01:30:40

giscus-bot giscus-bot 2022-12-16 22:16:51
Guest *Marcus R* @ 2013-02-02 12:12:14 originally posted:

Thanks a lot, I don't know how it got into the code. Now the simple script runs without problem.

May I ask another question. I intend to write my thesis in such a way that I can generate both Thesis, Presentation and other files out of the same file as described here:
http://people.su.se/~lundh/projects/compendium/

Professor Lundholm uses docstrip as a way to produce multiple output. Do you know of any other techniques to do this or is docstrip the way to go?

yihui yihui 2022-12-16 22:16:52

Article <--> tech report is easy (as in Lundholm's article); in knitr you can use child documents to decide whether to include certain parts of the document: http://yihui.name/knitr/demo/child/

But I think thesis <--> presentation from the same file is much more challenging because they are very different. However, it is easy to share code chunks between two documents if you use this: http://yihui.name/knitr/demo/externalization/ I know beamer has some support on conversion between article and presentation, but it does not make much sense to me. I'd rather start writing the presentation from scratch.

Originally posted on 2013-02-02 16:09:06

giscus-bot giscus-bot 2022-12-16 22:16:24
Guest *Honza* @ 2013-06-04 15:07:24 originally posted:

I completely agree with you on the advantage of the LaTeX example with R codes written in comments. But unfortunately Emacs ESS does not support it. Or does it?

yihui yihui 2022-12-16 22:16:53

No, it does not. The inertia is very strong :)

Originally posted on 2013-06-04 19:16:59

giscus-bot giscus-bot 2022-12-16 22:16:25
Guest *hcheng* @ 2013-10-22 03:43:57 originally posted:

Hi, I am very confused why the results are different when I use markdown and just run in Rstudio. In your markdown example, there are two lines: set.seed(123) rnorm(5). I get quite different results by running markdown and rstudio. For markdown, the results are what you provide in the output but in rstudio the results are 0.1870696 1.9960295 2.2993699 1.1274577 1.0811140. As I need to generate some simulated dataset, If i use the markdown, the results are far too different. Could you give me any clue?? Thanks!

yihui yihui 2022-12-16 22:16:54

That is unexpected. Are you sure you also copied set.seed(123) into RStudio? In other words, did you run exactly the same code in R Markdown and in RStudio console?

Originally posted on 2013-10-22 04:32:37

giscus-bot giscus-bot 2022-12-16 22:16:55
Guest *hcheng* @ 2013-10-22 14:58:31 originally posted:

Yes, I am pretty sure. Can you try ? I get the same result using R or Rstudio, but different in markdown. Even for the following lines , the result of Rstudio or R is [1] 3.612922.
So I'm quite confused.

set.seed(1213) # for reproducibility

x = cumsum(rnorm(100))
mean(x) # mean of x

[1] -1.939758

yihui yihui 2022-12-16 22:16:56

No, I still cannot reproduce it. Can you put sessionInfo() in your R Markdown code, and compare that with sessionInfo() in your R console?

Originally posted on 2013-10-22 20:00:22

giscus-bot giscus-bot 2022-12-16 22:16:57
Guest *JenHao Wu* @ 2014-09-11 19:48:02 originally posted:

Hi Yihui,

I have a similar problem. Instead of having different values from rnorm() which I have the same value after setting the same set.seed() in the set code chunk section in .Rnw file and in Rstudio, I have different results from WinBUGs (through R2WINBUGS package) even set the same bugs.seed. Do you have any suggestion for this problem? Thank you very much.

yihui yihui 2022-12-16 22:16:58

Do you mean WinBUGS and R generate different random numbers with the same seed? I do not know why that surprised you. R and WinBUGS should not be using exactly the same RNG's.

Originally posted on 2014-09-12 03:33:27

giscus-bot giscus-bot 2022-12-16 22:16:58
Guest *JenHao* @ 2014-09-12 19:12:34 originally posted:

Thank you for your promptly reply, Sorry I didn't make it clear in the beginning. I wrote my R code in Rstudio and link to WinBUGs through R2WinBUGs package, and now I call the same R script in Latex through knitr. And I have different result from running in Rstudio and Latex. I hope this is clear enough to let your know my problem. Thank you so much.

giscus-bot giscus-bot 2022-12-16 22:17:00
Guest *Yuanchun* @ 2015-06-04 21:22:10 originally posted:

Why the compile pdf does not show those plots?

giscus-bot giscus-bot 2022-12-16 22:16:25
Guest *David States* @ 2015-02-04 00:21:21 originally posted:

Would like to use LyX to edit knitr .Rnw files but having some problems getting started. Have R version 3.1.1 installed with the knitr library installed on a Mac running OS X 10.10.2 (Yeosemite).

First, LyX will not open .Rnw files directly, only .tex files. I guess this is by design, but it would be very useful if LyX could load .Rnw files directly and autoload the knitr module in the process.

Second issue, if I follow the description on this website, open a new file in LyX, load the knitr module and then try to import an existing .Rnw file (knitr-minimal.Rnw from this website), I get an error message from R:

An error occurred while running:

Rscript --verbos --no-save --no-restore
"Applications/http://LyX.app/Contents/Resources/scripts/lyxknitr.R"
"/Users/dstates/Documents/""knitr-minimal.Rnw"
"/Users/dstates/Documents/""knitr-minimal.tex" "/Users/dstates/Documents"

Sorry if I am missing something really basic here. Newby :(

giscus-bot giscus-bot 2022-12-16 22:16:59
Guest *Paul Rougieux* @ 2015-03-10 14:23:05 originally posted:

Start with the basic .lyx file knitr.lyx located on this page: http://yihui.name/knitr/demo/lyx/

giscus-bot giscus-bot 2022-12-16 22:16:26
Guest *Xing* @ 2015-03-31 14:24:20 originally posted:

Hi, Yihui, Can I just the R markdown Beamer-Presentation in Chinese?
I cannot make it

giscus-bot giscus-bot 2022-12-16 22:16:27
Guest *Stefano Lombardi* @ 2015-05-22 08:20:12 originally posted:

Hi Tihui,
I have a basic question. I am trying to replicate your 002-minimal.Rnw example.
After changing the weaving option to "knitr", I tried to compile the pdf, but I get this:

Quitting from lines 9-13 (knitr_minimal.Rnw)
Errore in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 3, 0

Note that if I delete the chunk of R code the pdf is compiled correctly.
Actually, whenever I try to embed any chunk of R-code the above error is reported.
Do you have any idea why this happens?

Thank you very much fro your work!
best,

Stefano

giscus-bot giscus-bot 2022-12-16 22:16:28
Guest *Paul Burger* @ 2015-06-12 15:50:00 originally posted:

Hi, Using RStudio Version 0.99.441 on Win8.1 (x32) with Miktex and RMarkdown; I cannot get your minimal PDF example to compile. Knitr cannot find inputnc.sty but everything seems to indicate that inputnc was superceded by inputenc.sty and that exists in Miktex. Can you explain the problem?

Here is the output log:
processing file: test.Rmd
|............. | 20%
ordinary text without R code
|.......................... | 40%
label: unnamed-chunk-1
|....................................... | 60%
ordinary text without R code
|.................................................... | 80%
label: unnamed-chunk-2 (with options)
List of 1
$ echo: logi FALSE
|.................................................................| 100%
ordinary text without R code

"H:/program files/RStudio/bin/pandoc/pandoc" test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output test.pdf --template "h:PROGRA~1RR-32~1.0libraryRMARKD~1rmdlatexdefault.tex" --highlight-style tango --latex-engine pdflatex --variable "geometry:margin=1in"
output file: test.knit.md

! LaTeX Error: File `inputnc.sty' not found.

Type X to quit or to proceed,
or enter new name. (Default extension: sty)
Enter file name:
! Emergency stop.
<read *="">
l.79
pandoc.exe: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
In addition: Warning message:
running command '"H:/program files/RStudio/bin/pandoc/pandoc" test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output test.pdf --template "h:PROGRA~1RR-32~1.0libraryRMARKD~1rmdlatexdefault.tex" --highlight-style tango --latex-engine pdflatex --variable "geometry:margin=1in"' had status 43
Execution halted

giscus-bot giscus-bot 2022-12-16 22:16:29
Guest *Young* @ 2015-07-09 19:55:27 originally posted:

@yihui:disqus Hi, I am trying to learn knitr. I started with your basic example "knitr-minimal.Rnw"; however, the pdf file I get does not include the figures. I am running exactly what you have included without any modeification. What is the problem?

yihui yihui 2022-12-16 22:17:01

You are most likely to be using Sweave instead of knitr: http://yihui.name/knitr/demo/rstudio/

Originally posted on 2015-07-09 22:38:31

giscus-bot giscus-bot 2022-12-16 22:16:30
Guest *🐉®γσ ξηg* @ 2015-10-15 10:59:07 originally posted:

paragraph 1...

gc(reset=TRUE)  

paragraph 2...

I got a question about recall chunk. May I know how do I recall the chunk reset after paragraph 2?

giscus-bot giscus-bot 2022-12-16 22:16:32
Guest *joe* @ 2015-12-29 00:37:41 originally posted:

when will it be possible to use ggvis on Rnw knitr documents to produce pdf? (With Windows, where it's not possible to get a working Vega)

giscus-bot giscus-bot 2022-12-16 22:16:33
Guest *Khagay Na* @ 2016-12-04 19:46:47 originally posted:

is there any way to use bash syntax in Rrst documents? I thought .. {bash name} would be a replacement but, it's not.

yihui yihui 2022-12-16 22:17:02

You can only use the chunk option engine='bash' for documents that are not R Markdown.

Originally posted on 2016-12-07 16:34:18

Sign in to join the discussion

Sign in with GitHub