I need to allocate (using C nomenclature) a set of "global" variables, some 
integer scalars and some double vectors. 
I have placed the name of such variables in the file containing the main script 
and the called functions:

# ----------------------------------------------------------------------------
# ---------------------------  GLOBAL DATA & CONSTANTS  ----------------------
 EntrThreshold <- 1.e+35
 NCMAX  <- 50

 ncof   <- 0 
 ioff   <- 0
 joff   <- 0
 sig    <- 0.0

 cc     <- vector(length=NCMAX)
 cr     <- vector(length=NCMAX)

Function "pwtset", called by function "ford", changes the content of variable 
'ncof' as confirmed by the debigging printed values. 
But when function "pwset" exits and the flow control returns to the caller 
"ford" then variable 'ncof' has not kept the value assigned by "pwset", as if 
function "pwset" had allocated its own variable 'ncof'.
My question is: how can I have R interpreter allocate "global"variables visible 
and accessible by all the functions in the same file ?


"pwtset" <- function(n) {

cat("\n BEGIN 'pwtset' \n")

 if(n < 100){
   ncof <- n
 }else{
   ncof <- n -100
 }
 ........
 }


 BEGIN 'pwtset' 

 function 'pwtset': ncof =  4 

 END 'pwtset' 

 function 'ford': BEFORE calling wt1, ncof:  0 


Thank you very much for removing my confusion.
Maura 




tutti i telefonini TIM!


        [[alternative HTML version deleted]]

______________________________________________
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