12

Is there a simple way to create R documentation file for simple R functions?

I know I can edit a .Rd file in R-studio and preview it in HTML file. But how to put it into latex to edit and preview? Is there some latex package producing R documentation format?

ymn
  • 2,175
  • 2
  • 21
  • 39
user1896629
  • 121
  • 1
  • 3
  • 2
    Can you give some more context for why you need to do this? Are you trying to write a single, stand-alone documentation file? Are you writing a package? – joran Dec 12 '12 at 04:32
  • 1
    Rd files use their own simplified markup language; usually they are written by hand, but a more scalable solution is to use roxygen2 to produce the Rd files for you from comments in the source file. – baptiste Dec 12 '12 at 18:28

5 Answers5

10

There is the Rd2latex function in the tools package that will convert from the .Rd format to LaTeX format. This will let you preview the documentation in LaTeX. However this does not allow converting edits to the LaTeX document back to the .Rd document.

Greg Snow
  • 48,497
  • 6
  • 83
  • 110
  • Sure, sure, thought it was more polite to comment than to plough over your post. Shall we just remove these comments too? I'll start... – Dirk Eddelbuettel Dec 12 '12 at 17:03
2

Look at Sweave, maybe it helpful for you.

Sweave is a tool that allows to embed the R code for complete data analyses in latex documents.

The purpose is to create dynamic reports, which can be updated automatically if data or analysis change. Instead of inserting a prefabricated graph or table into the report, the master document contains the R code necessary to obtain it. When run through R, all data analysis output (tables, graphs, etc.) is created on the fly and inserted into a final latex document.

The report can be automatically updated if data or analysis change, which allows for truly reproducible research.

ymn
  • 2,175
  • 2
  • 21
  • 39
1

Check out printr http://yihui.name/printr/ . It should do what you need if you are using knitr.

The problem with Rd2latex is that i haven't figured out which style file I need to use, otherwise it works fine.

Marco Stamazza
  • 836
  • 9
  • 15
1

When you generate the latex code with the Rd2latex function, make sure that you copy the Rd.sty file from the R directory, paste it and somewhere that latex can see it and use \usepackage{Rd}.

savas
  • 51
  • 1
  • 4
0

Try the knitr package, an easy way to generate flexible and fast dynamic reports with R for LaTex.

tfr
  • 71
  • 7