[R] Retrieving objects from functions...
Kevin Wang
Kevin.Wang at maths.anu.edu.au
Thu Sep 30 09:59:40 CEST 2004
Hi,
On Thu, 30 Sep 2004, Jonathan Harris wrote:
> I've written a program that involves a loop that creates a matrix. I'd
> like to be able to manipulate that matrix on my R desktop, but after I
> run the function, that matrix does not appear when I type ls(). How can
> I make that matrix become an object that I can manipulate?
If I understand you right, you want something like:
foo <- function() {
goo <- matrix(1:10, nrow = 5, ncol = 2)
}
then be able to call goo after running foo()? If this is what you want,
then you need to do something like:
foo <- function() {
goo <<- matrix(1:10, nrow = 5, ncol = 2)
}
to force goo to become a global variable, instead of a local variable to
foo().
HTH,
Kevin
--------------------------------
Ko-Kang Kevin Wang
PhD Student
Centre for Mathematics and its Applications
Building 27, Room 1004
Mathematical Sciences Institute (MSI)
Australian National University
Canberra, ACT 0200
Australia
Homepage: http://wwwmaths.anu.edu.au/~wangk/
Ph (W): +61-2-6125-2431
Ph (H): +61-2-6125-7407
Ph (M): +61-40-451-8301
More information about the R-help
mailing list