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? 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? Thank you very much! Baiyi Song Computer engineering institute Dortmund University
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
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