On 03/08/2008 12:13 PM, Jonas wrote:
Duncan, Patrick,

Sorry for not being very clear (and having non-working code in my
example). What I'm actually trying to achieve is creating a wrapper
around the NelsonSiegel function in the fBonds package in order to
(among other things) create my own plot function. However, all of the
objects i would like to access inside of my.function are not returned
by the NelsonSiegel function. The are only local inside the
NelsonSiegel function. Is there a way to inside my wrapper function
access these objects?

 my.function() <- {
    z <- NelsonSiegel(Yield, Maturity, doplot=FALSE)
    #here i would like to access objects not returned by NelsonSiegel
}

No, as Patrick said, once the function returns all the locals (other than z) disappear. You need to get the source to the function and modify it.

Duncan Murdoch



//Jonas

On Sun, Aug 3, 2008 at 6:05 PM, Patrick Burns <[EMAIL PROTECTED]> wrote:
Duncan Murdoch wrote:
On 03/08/2008 11:29 AM, Jonas wrote:
hi,

my apologies if this has been covered numerous times before and it's
only my lack of search and/or R skills that is  stopping me from
finding the solution.
i'm trying to access an object defined and created inside a function
(the object is not returned by the function), but i can't seem to get
it to work, i keep getting an "object not found" error message. i
thought the solution where to be found in changing the
frame/environment. but i can't seem to understand how do do it
correctly. what i want to do is something like:

my.function() <- {
  function.from.package(x,y)
  plot (object.inside.package.function)
}
That pseudo-code doesn't really make sense: you didn't save the result of
function.from.package() anywhere.  If you change it to

 my.function() <- {
   z <- function.from.package(x,y)
   plot (z)
 }

then it's perfectly standard.  So the question is:  where are you
expecting R to look to find object.inside.package.function?
I suspect the OP doesn't care where R looks as
long as it finds it.  The fact that everything about
'function.from.package' except 'z' has been sucked
down a black hole by the time 'plot' is on the scene
is going to make that search impossible.

One solution is to create 'my.function.from.package'
and change the return value to include
'object.inside.package.function'.

Patrick Burns
[EMAIL PROTECTED]
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")
Duncan Murdoch

i'm using R 2.7.1 on linux

sincerely,
jonas

______________________________________________
R-help@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.
______________________________________________
R-help@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.



______________________________________________
R-help@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.

Reply via email to