开发者

How do I convert Rd files to pdf for a package that I am creating in R?

开发者 https://www.devze.com 2023-01-17 13:02 出处:网络
I am writing a package in开发者_StackOverflow R and I would appreciate some example bash code to process the Rd filesto latex and then to pdf.

I am writing a package in开发者_StackOverflow 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


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.


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)))


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"


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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消