[R] Two questions about the creating new package

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Dec 2 17:36:31 CET 2003


On Tue, 2 Dec 2003, Song Baiyi wrote:

> Hello everyone,
> 
> I am just trying to colloct all my function into a new packages. I met 
> two questions which hurt me so much:
> 
> 1. when I use the "prompt" to help to write Rd file for a variable x 
> which is character vector, say x <- c("a","b"), it always give the error 
> informaion:
> Error in get(x, envir, mode, inherits) : variable "a" was not found.
> Obvious it regards the "a" as the variable name instead of the item of a 
> vector. So how can I put a character vector into the pacakge, or it must 
> be a data.frame to put into a package?

are you saying prompt(x) or prompt("x") or prompt(name="x")?  The latter
two work.  Note also the Warning on the help page for prompt.

> 2. Also about the constant character vector. I have a constant vector 
> which record the column names. I hope when the package is loaded, this 
> vector will be loaded without explict writing "data(***)". Therefore the 
> users and other functions can use it. How can I do it? A more generate 
> question is where should I put those R codes which will be excuted after 
> the package is loaded?

If you put code in a file say MyPkgSources/R/zzz.R it is executed on
loading, and that can assign a constant character vector.  It is often
better to put code in a .First.lib function, though.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list