[R] Two questions about the creating new package

Jason Turner jasont at indigoindustrial.co.nz
Tue Dec 2 18:01:40 CET 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?

Use the "name" argument to prompt.

prompt(name="x")

should work.

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

See help(.First.lib) .  In this case, you'd want something like....

.First.lib <- function(lib,pkg){
   data(foo)
}

When writing a package, these functions are traditionally (but not 
manditorily) stored in a file called zzz.R .

Cheers

Jason
-- 
Indigo Industrial Controls Ltd.
http://www.indigoindustrial.co.nz
64-21-343-545
jasont at indigoindustrial.co.nz




More information about the R-help mailing list