1

I am a new user of R and R Markdown and understand that R markdown has some functionality to compile PDF documents that include R script.

I have two questions:

  1. Does R markdown have the same flexibility to handle Latex and any packages (perhaps similar to TexStudio for example)?
  2. As an alternative, is it possible to include R script / code chunks in a tex file and use TexStudio to compile the PDF, rather than use R markdown?

In my recent experience, I have found that R markdown is quite tedious to handle Latex in the same way that TexStudio might and I would be keen to hear thoughts or views on the advantages or disadvantages of each approach.

Thanks!

3

Does R markdown have the same flexibility to handle Latex?

As all R markdown structures are completely converted to LaTeX, and moreover, you can include extra custom LaTeX code via custom templates, YAML headers, or direct commands/environments between the markdown text (that are omitted when exporting to other formats), really it has more flexibility.

As an alternative, is it possible to include R script / code chunks in a tex file

Yes, it's what RStudio refers to as "Sweave documents" (files with extension .Rnw)

and use TexStudio to compile the PDF, rather than use R markdown?

You can compile .Rmd files from the command line of the OS, as well as .Rnw files (see How to build Knitr document from the command line for details), or using any text editor configurable to run a custom sequence of external programs taking the edited file.

I would be keen to hear thoughts or views on the advantages or disadvantages of each approach.

RStudio editor is not very good in some aspects, as the spell checker or the management of some odd characters such as "→" (that produce wrong cursor positions) but it is designed to manage specifically .R, .Rmd and .Rnw files

Every LaTeX editor could have this or that feature that is not RStudio, but hardly you will have comparable facilities to make/test R code, compose R chunks in .Rmd and .Rnw files, and compile to several formats.

For instance, TexSudio is not at all a markdown editor. You can edit a .Rmd file with this program, but as with any other plain text editor, i.e., without access to a outline, without markdown syntax highlight, without preview of images, etc.

But nothing prevents you from using some editor of your choice to take advantage of some nice feature (as a real-time spelling checker, for instance), save the file and continue in RStudio.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.