Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create and save R's default codebooks as a pdf

If I load data(mtcars) it comes with a very neat codebook that I can call using ?mtcars.

I'm interested to document my data in the same way and, furthermore, save that neat codebook as a pdf.

Is it possible to save the 'content' of ?mtcars and how is it created?

Thanks, Eric

P.S. I did read this thread.

update 2012-05-14 00:39:59 PDT

I am looking for a solution using only R; unfortunately I cannot rely on other software (e.g. Tex)

update 2012-05-14 09:49:05 PDT

Thank you very much everyone for the many answers.

Reading these answers I realized that I should have made my priorities much clearer. Therefore, here is a list of my priorities in regard to this question.

  1. R, I am looking for a solution that is based exclusively on R.
  2. Reproducibility, that the codebook can be part of a automated script.
  3. Readability, the text should be easy to read.
  4. Searchability, a file that can be open with any standard software and searched (this is why I thought pdf would be a good solution, but this is overruled by 1 through 3).

I am currently labeling my variables using label() from the Hmisc package and might end up writing a .txt codebook using Label() from the same package.

like image 891
Eric Fail Avatar asked May 14 '12 02:05

Eric Fail


2 Answers

(I'm not completely sure what you're after, but):

  • Like other package documentation, the file for mtcars is an .Rd file. You can convert it into other formats (ASCII) than pdf, but the usual way of producing a pdf does use pdflatex.

  • However, most information in such an .Rd file is written more or less by hand (unless you use yet another R package like roxygen/roxygen2 help you to generate parts of it automatically.

  • For user-data, usually Noweb is much more convenient.
    .Rnw -Sweave-> -> .tex -pdflatex-> pdf is certainly the most usual way with such files. However, you can use it e.g. with Openoffice (if that is installed) or use it with plain ASCII files instead of TeX.

  • Have a look at package knitr which may be easier with pure-ASCII files. (I'm not an expert, just switching over from Sweave)

  • If html is an option, both Sweave and knitr can work with that.

like image 64
cbeleites unhappy with SX Avatar answered Nov 19 '22 21:11

cbeleites unhappy with SX


I don't know how to get the pdf of individual data sets but you can build the pdf of the entire datasets package from the LaTeX version using:

path <- find.package('datasets')
system(paste(shQuote(file.path(R.home("bin"), "R")),"CMD", 
    "Rd2pdf",shQuote(path)))

I'm not sure on this but it only makes sense you'd have to have some sort of LaTeX program like MikTex. Also I'm not sure how this will work on different OS as mine is windows and this works for me.

PS this is only a partial answer to your question as you want to do this for your data, but if nothing else it may get the ball rolling.

like image 4
Tyler Rinker Avatar answered Nov 19 '22 22:11

Tyler Rinker