Re: [R] writintg wrappers around save()

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Fri, 21 Mar 2008 21:06:13 +0000 (GMT)

>From the help page

      The names of the objects specified either as symbols (or character
      strings) in '...' or as a character vector in 'list' are used to
      look up the objects from environment 'envir'.

The default for envir is parent.frame(). You want to change it (and watch out that default and explicit arguments are evaluated in different places). One approach is

save.verbose <- function(..., file, envir = parent.frame()) {

     cat("save.verbose:", file, "\n")
     save(..., file=file, envir=envir)

}

On Fri, 21 Mar 2008, Vadim Organovich wrote:

> Dear R-users,
>
> I am trying to write a wrapper function around save() that will report the file which is being saved to.
>
> So I thought that the followintg would do the trick, but it doesn't. I understand that 'y' is somehow not visible inside save.verbose, but don't know how to fix this.
>
> save.verbose <- function(..., file) {
> cat("save.verbose:", file, "\n")
> save(..., file=file)
> }
>> foo <- function(x) { y <- x; save.verbose('y', file='foo.rda') }; foo(1)
> save.verbose: foo.rda
> Error in save(..., file = file) : object 'y' not found
> Any suggestion how to fix this?
>
> Thank you for your time,
> Vadim
>
> P.S. I have a nagging feeling that I've already asked this question but I am not able to find any trace of it in the archives. My apologiesif this is so.
>
> [[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 Fri 21 Mar 2008 - 21:13:31 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 Fri 21 Mar 2008 - 22:30:22 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