Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using an R Markdown style document (.Rmd) as input for Pweave

I'm trying to run a basic R Markdown document (that calls python in code chunks) through Pweave. In the Pweave documentation it states that you can declare code chunks using the style ```{python}. However when I try to compile using, for example, pweave -f pandoc FIR_design.mdw the chunks are not run and instead placed in verbatim.

All the examples in the documentation use the noweb syntax e.g.

<<fig = True, width = '12 cm', echo = False>>=
from pylab import *
plot(arange(10))
show()
@

The markdown equivalent would be:

```{python, fig = True, width = '12 cm', echo = False}
from pylab import *
plot(arange(10))
show()
```

When I try to run the examples using the markdown syntax it simply adds them in verbatim and doesn't run the chunk. Is this expected? If so, how should I be converting my .Rmd documents to make them runable in Pweave. Must I convert them to noweb style?

Here is the documentation example document FIR_design.mdw rewritten in .Rmd format (for examples):

  • FIR_design.Rmd
like image 767
James Owers Avatar asked Jun 26 '16 14:06

James Owers


People also ask

How do you r markdown in knitting?

There are two ways to render an R Markdown document into its final output format. If you are using RStudio, then the “Knit” button (Ctrl+Shift+K) will render the document and display a preview of it. Note that both methods use the same mechanism; RStudio's “Knit” button calls rmarkdown::render() under the hood.

How do you hyperlink in RMD?

Hyperlinks are created using the syntax [text](link) , e.g., [RStudio](https://www.rstudio.com) . The syntax for images is similar: just add an exclamation mark, e.g., ![ alt text or image title](path/to/image) . Footnotes are put inside the square brackets after a caret ^[] , e.g., ^[This is a footnote.] .

What is the difference between Markdown and Rmarkdown?

R Markdown is an extension of the markdown syntax. R Markdown files are plain text files that typically have the file extension . Rmd . They are written using an extension of markdown syntax that enables R code to be embedded in them in a way which can later be executed.

How do I embed code in R markdown?

You can insert an R code chunk either using the RStudio toolbar (the Insert button) or the keyboard shortcut Ctrl + Alt + I ( Cmd + Option + I on macOS).


1 Answers

Instead of pweave -f pandoc <source> try using pweave -i markdown <source>.

If you do not provide the input format, it is deduced from file extension. As you can see in linked source, your input file needs to have the .md extension for it to be auto-detected as "Pandoc markdown" formatted.

The default output format seems to be the same as input, or as provided with --format (-f).

like image 146
tutuDajuju Avatar answered Nov 14 '22 21:11

tutuDajuju