I am working on a package in R, and am looking for a way to document the sources of external data stored in the inst/extdata folder. I know that data in the /data folder can be documented with roxygen as per this SO post.
The trouble seems to be that external data is not exported into the namespace of the package, and therefore tying an roxygen help document to it poses an issue. Is there a way to overcome this and to document external data similar to the method for items in the /data folder?
Here is the reproducible (on linux) example of solution I provided in comments.
Code below will create minimal package
defining dummy DESCRIPTION file
example ext/data/data1.csv csv data file
example man/data1.Rd R documentation file
Then it will build and install package.
mkdir -p my.pkg
cat > my.pkg/DESCRIPTION <<EOL
Package: my.pkg
Type: Package
Title: My pkg
Version: 1.0.0
Description: Example my pkg.
License: GPL-3
EOL
mkdir -p my.pkg/inst/extdata
cat > my.pkg/inst/extdata/data1.sv <<EOL
a,b,c
1,a,2.5
2,b,5.5
EOL
mkdir my.pkg/man
cat > my.pkg/man/data1.Rd <<EOL
\name{data1}
\alias{data1}
\alias{data5}
\title{
my data
}
\description{
desc of data.
}
EOL
R CMD build my.pkg
R CMD INSTALL my.pkg_1.0.0.tar.gz
Now see that manual can be found
Rscript -e 'library(my.pkg); ?data1'
Rscript -e 'library(my.pkg); ?data5'
As you can see we can refer to documentation of extdata using any name defined in alias inside Rd file.
Related
Every package on CRAN seems to provide a reference manual but in contrast to vignettes they do not seem to get downloaded or built when installing packages. Can this be done so that I can access them from the command line in R or can I only access them on CRAN?
From a given package's sources, you can build this via R CMD Rd2pdf:
edd#max:~$ R CMD Rd2pdf --help
Usage: R CMD Rd2pdf [options] files
Generate PDF output from the Rd sources specified by files, by
either giving the paths to the files, or the path to a directory with
the sources of a package, or an installed package.
Unless specified via option '--output', the basename of the output file
equals the basename of argument 'files' if this specifies a package
or a single file, and 'Rd2' otherwise.
The Rd sources are assumed to be ASCII unless they contain \encoding
declarations (which take priority) or --encoding is supplied or if using
package sources, if the package DESCRIPTION file has an Encoding field.
The output encoding defaults to the package encoding then to 'UTF-8'.
Files are listed in the order given: for a package they are in alphabetic
order of the \name sections.
Options:
-h, --help print short help message and exit
-v, --version print version info and exit
--batch no interaction
--no-clean do not remove created temporary files
--no-preview do not preview generated PDF file
--encoding=enc use 'enc' as the default input encoding
--outputEncoding=outenc
use 'outenc' as the default output encoding
--os=NAME use OS subdir 'NAME' (unix or windows)
--OS=NAME the same as '--os'
-o, --output=FILE write output to FILE
--force overwrite output file if it exists
--title=NAME use NAME as the title of the document
--no-index do not index output
--no-description do not typeset the description of a package
--internals typeset 'internal' documentation (usually skipped)
--build_dir=DIR use DIR as the working directory
The output papersize is set by the environment variable R_PAPERSIZE.
The PDF previewer is set by the environment variable R_PDFVIEWER.
Report bugs at bugs.r-project.org .
edd#max:~$
I created a local R package using roxygen2 and devtools. It seem work well but I would like to know how I get the complete PDF documentation then. Since the DESCRIPTION and .Rd files are created by roxygen2 automatically, I'd think there's a easy way to translate them into a single PDF document.
I think there's a command here for you: R CMD Rd2pdf. From its help:
edd#max:~$ R CMD Rd2pdf --help
Usage: R CMD Rd2pdf [options] files
Generate PDF output from the Rd sources specified by files, by
either giving the paths to the files, or the path to a directory with
the sources of a package, or an installed package.
Unless specified via option '--output', the basename of the output file
equals the basename of argument 'files' if this specifies a package
or a single file, and 'Rd2' otherwise.
The Rd sources are assumed to be ASCII unless they contain \encoding
declarations (which take priority) or --encoding is supplied or if using
package sources, if the package DESCRIPTION file has an Encoding field.
The output encoding defaults to the package encoding then to 'UTF-8'.
Files are listed in the order given: for a package they are in alphabetic
order of the \name sections.
Options:
-h, --help print short help message and exit
-v, --version print version info and exit
--batch no interaction
--no-clean do not remove created temporary files
--no-preview do not preview generated PDF file
--encoding=enc use 'enc' as the default input encoding
--outputEncoding=outenc
use 'outenc' as the default output encoding
--os=NAME use OS subdir 'NAME' (unix or windows)
--OS=NAME the same as '--os'
-o, --output=FILE write output to FILE
--force overwrite output file if it exists
--title=NAME use NAME as the title of the document
--no-index don't index output
--no-description don't typeset the description of a package
--internals typeset 'internal' documentation (usually skipped)
The output papersize is set by the environment variable R_PAPERSIZE.
The PDF previewer is set by the environment variable R_PDFVIEWER.
Report bugs at bugs.r-project.org .
edd#max:~$
I have some R code that I'd like to share with other people in my office, and also run periodically on our servers. We all have Windows 7 desktops, and the servers run Red Hat Enterprise Linux.
I've been through the docs, and I'm stuck. None of the following have all the necessary steps, detail the correct folder structure, or tell me how to build a Linux package, or build a Windows package on Linux.
http://cran.r-project.org/doc/contrib/Leisch-CreatingPackages.pdf
http://cran.r-project.org/doc/manuals/R-admin.html#Setting-up-a-package-repository
Creating a local R package repository
So I have my code in git.
$ mkdir ~/daveStuff
$ cd ~/daveStuff
$ git init
$ git remote add origin git#davez0r.co:/opt/git/daveStuff.git
$ git pull origin master
Now in my home directory I have this folder structure:
daveStuff
|-- DESCRIPTION
|-- R
|-- stuff.R
|-- exec
|-- script.R
My description file looks like this:
Package: daveStuff
Type: Package
Title: What the package does (short line)
Version: 1.0
Date: 2014-02-03
Author: Who wrote it
Maintainer: Who to complain to <yourfault#somewhere.net>
Description: More about what it does (maybe more than one line)
License: What license is it under?
I'm running apache on one of my servers. So I added this:
/var/www/html/R/src/contrib/3.0/
This correctly maps to the following, where I read any files I put there:
http://davez0r.co/R/src/contrib/3.0/
What I'd like to be able to do is the following, from either Windows or Linux:
> install.packages("daveStuff", repos="http://davez0r.co/R", type="source")
> library(daveStuff)
So first step is that I need to turn my library into a package.
$ cd ~ # one under the "daveStuff" directory
$ R CMD build daveStuff
This creates a zip file:
~/daveStuff_1.0.tar.gz
Now I copy that file to my repository location:
$ cp ~/daveStuff_1.0.tar.gz /var/www/html/R/src/contrib/3.0/
Now if I go like this:
> install.packages("daveStuff", repos="http://davez0r.co/R", type="source")
Warning in install.packages :
unable to access index for repository http://davez0r.co/R/src/contrib
It gives me that error message saying that it can't find the package. So I create a package manifest:
$ cd /var/www/html/R/src/contrib # one under where I put the archive
$ Rscript -e 'tools::write_PACKAGES(".", type="source", subdirs=TRUE)'
This gives me a PACKAGES file:
Package: daveStuff
Version: 1.0
MD5sum: 817bbfedeb218ce0331dd7108408c5e6
NeedsCompilation: no
Path: ./3.0
Now it works when I try to load it:
> install.packages("daveStuff", repos="http://davez0r.co/R", type="source")
Unresolved issues:
I've lost the scripts that were in the exec directory.
Should I wrap these in functions and include them in the library?
Should I stick with source packages?
How do I make Windows binary packages on Linux?
It seems to me that you skipped one final step.
One needs
A local package (which you have)
Tarballs for Linux and binary packages for Windows (not sure)
A local repository (which you started)
Meta-data on your repository (which you seem to miss)
I do that at work for similar setup (some Windows, lots of Linux) via a simple script:
#!/bin/bash
## see e.g.
## http://cran.r-project.org/doc/manuals/R-admin.html\
## #Setting-up-a-package-repository
## http://stackoverflow.com/questions/2905650/creating-a-local-cran-repository
ver=3.00
rsync -vu *tar.gz /SomeServer/R/src/contrib/
rsync -vu *zip /SomeServer/R/bin/windows/contrib/${ver}/
cd /SomeServer/R/src/contrib/
r -e 'tools::write_PACKAGES(".", type="source")'
cd /SomeServer/R/bin/windows/contrib/${ver}/
r -e 'tools::write_PACKAGES(".", type="win.binary")'
I use littler's r binary here, you could equally well use Rscript.
I have a R package in the directory ~/package; I also keep the output from my use of the package in the directory ~/package/out. When the content of ~/package/out gets very large, it takes minutes instead of seconds to build this package. Is there a way to have "R CMD build package" ignore the ~/package/out directory?
You are a little short on details about what is in there --- but R CMD respects .Rbuildignore.
Here is a real example:
edd#max:~$ cat svn/rinside/pkg/.Rbuildignore
inst/doc/html
inst/doc/latex
inst/doc/man
inst/doc
inst/lib
edd#max:~$
which tells R CMD build to ignore the doxygen=-generated documentation, as well as a library directory.
See the documentation on the .Rbuildignore file in building packages section of the R-Extensions manual.
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
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
}