Re: [R] package.skeleton from within function: objects not found

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Mon, 28 Jan 2008 08:30:30 +0000 (GMT)

You need to set the 'environment' argument (the help file is incomplete). e.g.

env <- sys.frames()[[sys.nframe()]]
package.skeleton(name = pkgName, list=c("f","e", "myenv"), env=env)

On Mon, 28 Jan 2008, Tineke Casneuf wrote:

> Hi all,
>
> I ran into a strange error: I am trying to create a package skeleton for a
> new source package from within a function. Objects that are created in this
> function are to be included in my package, but for some reason, I get an
> error message saying that these objects cannot be found.
>
> Here is the code:
> ######
> myfun <- function(pkgName,x){
> myenv <- new.env()
> apply(x, 1, function(row){
> assign(row[1], row[2], envir=myenv)
> })
> f <- function(x,y) x+y
> e <- rnorm(1000)
> # browser()
> package.skeleton(name = pkgName, list=c("f","e", "myenv"))
> return(myenv)
> }
> x <- data.frame(keys = LETTERS[1:5], values = 1:5)
> myfun("test", x)
> ######
>
> And my sessionInfo:
>> sessionInfo()
> R version 2.6.1 (2007-11-26)
> i386-pc-mingw32
> locale:
> LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
> States.1252;LC_MONETARY=English_United
> States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>>
> I did not find anything referring to this problem in the help page, on the R
> mailing list or wiki. Has anyone noticed this or can someone explain to me
> why my objects cannot be found?
>
> Many thanks in advance,
> best wishes,
>
> Tine
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 28 Jan 2008 - 08:32:57 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 28 Jan 2008 - 12:30:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive