Dear R-helpers,

I try to use nested R-functions as follows:

help1 = function(){
        x = 1
        help2()
}

with

help2 = function(){
        if (x == 1)
                cat("Hello world x = 1")
}

If I compile these functions and run help1()
an error message occurs
        Fehler in help2() : objekt "x" nicht gefunden

in english "error in help2(): object "x" not found"

If I change help1 to

help1 = function(){
        x <<- 1
        help2()
}

so that "x" is now defined at the global environment it works fine.
But the problem is, now "x" is defined also outside of help1 and this is 
not desired !

Is there any usable solution for this problem?
But, the original problem is to assign new values for "x" in help1 inside 
help2 !

Thanks in advance
 
Jörg Betzin
---------------------------------------------------
Deutsches Zentrum für Altersfragen
Manfred-von-Richthofen-Str. 2
12101 Berlin
Tel. (030) 260740-20
E-Mail: joerg.bet...@dza.de
URL: http://www.dza.de
---------------------------------------------------

        [[alternative HTML version deleted]]

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to