16
votes

I am writing a package in R and I would appreciate some example bash code to process the Rd files to latex and then to pdf.

It is in the directory ~/mypkg/dev/. I have generated the file structure and Rd templates.

from ~/mypkg/dev/man, I have tried

R CMD Rdconv -o mypkg-package.tex --type=latex mypkg-package.Rd

mypkg-package.tex file is generated, but

pdflatex mypkg-package.tex

generates tex without any preamble.

I have read the documentation in "Writing R extensions" and "R CMD Rdconv --help" on this subject, but no examples are provided.

Thank you

4

4 Answers

19
votes

There are two issues here:

First, the Rdconv command only transforms one Rd file at a time; your question suggests that you want the full manual.

Second, the Rd2dvi command is your friend. I just ran the following on a local package:

R CMD Rd2dvi --pdf --title='Test of foo' -o /tmp/foo.pdf man/*.Rd

That should be what you asked for.

5
votes

Try this. It worked for me. found from Making an R package PDF manual using devtools

pack <- "name_of_your_package"

path <- find.package(pack)

system(paste(shQuote(file.path(R.home("bin"), "R")),"CMD", "Rd2pdf", shQuote(path)))
4
votes

0. From question, it is assumed that you have .Rd files.

You may have obtained these .Rd files via roxygen package or some other ways. You need .pdf of your package. One way to do this is from Windows's command line.

1. Open Windows Command Prompt (in Administrator mode, if possible). Start - type "cmd" - (optional: right click the appearing icon - Run as administrator)

2. Pass to the R's current working directory (it can be found via "getwd()" in R's console) in the command propmt. R's current working directory contains the folder with your package source.

cd C:\Users\erdogan\Documents\Revolution

3. For the sake of argument, say the package folder was called "causfinder". Run the following command in Windows command prompt:

(be sure that you have not got any causfinder.pdf in R's working directory (You may have obtained some R-development-incompatible causfinder.pdf with some other ways outside R). If there exists, delete causfinder.pdf first. Otherwise, you get this error: "file 'causfinder.pdf' exists; please remove it first")

R CMD Rd2pdf causfinder/

This command performs .Rd --> LateX --> .pdf process automatically. You obtain causfinder.pdf in R's working directory.

This is further described in the manual on Writing R Extensions under the section on "Processing documentation files"

1
votes

I have created a basic bash function, so I can just run rdoc from my command line. It generates the Rd files, creates the pdf, and opens it. I only use it for testing, not for creating the final documentation. You can add it by adding the following function to your .bashrc (or whichever you use) file

rdoc() {
  echo -e "devtools::document()" | R --no-save
  rm /tmp/rdoc.pdf
  R CMD Rd2pdf -o /tmp/rdoc.pdf man/*.Rd
  open /tmp/rdoc.pdf
}