[R] access object inside a function

Duncan Murdoch murdoch at stats.uwo.ca
Sun Aug 3 17:34:32 CEST 2008


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?

Duncan Murdoch

> 
> i'm using R 2.7.1 on linux
> 
> sincerely,
> jonas
> 
> ______________________________________________
> 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.



More information about the R-help mailing list