[Rd] private variables in package.

Vladimir Eremeev wl2776 at gmail.com
Fri May 25 14:13:27 CEST 2007


I do use this function.
Here is the example session, run from the newly created directory, without
.Rdata and .Rhistory files.

=== begin
R version 2.5.0 Patched (2007-05-13 r41549)
Copyright (C) 2007 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(ac9)
> AB2C(matrix(rnorm(90),ncol=9),matrix(rnorm(90),ncol=9))
Error in AB2C(matrix(rnorm(90), ncol = 9), matrix(rnorm(90), ncol = 9)) : 
        object "ac9nw" not found
> options(error=recover)
> AB2C(matrix(rnorm(90),ncol=9),matrix(rnorm(90),ncol=9))
Error in AB2C(matrix(rnorm(90), ncol = 9), matrix(rnorm(90), ncol = 9)) : 
        object "ac9nw" not found

Enter a frame number, or 0 to exit   

1: AB2C(matrix(rnorm(90), ncol = 9), matrix(rnorm(90), ncol = 9))

Selection: 1
Called from: eval(expr, envir, enclos)
Browse[1]> ls()
[1] "a"          "b"          "model.type" "nwa"        "nwb"       
[6] "nza"        "nzb"       
Browse[1]> search()
 [1] ".GlobalEnv"        "package:ac9"       "package:stats"    
 [4] "package:graphics"  "package:grDevices" "package:utils"    
 [7] "package:datasets"  "package:methods"   "Autoloads"        
[10] "package:base"     
Browse[1]> n

Enter a frame number, or 0 to exit   

1: AB2C(matrix(rnorm(90), ncol = 9), matrix(rnorm(90), ncol = 9))

Selection: 1
Browse[1]> n

Enter a frame number, or 0 to exit   

1: AB2C(matrix(rnorm(90), ncol = 9), matrix(rnorm(90), ncol = 9))
Selection: 0


=== Pause of the session, don't quit from R.

The function AB2C tries to work, if I use the data function.
But this data function makes the ac9nw visible in the global environment.

=== Continuing the sample session:

> data(ac9nw)
> ls()
[1] "ac9nw"
> ac9nw
[1] 9

> AB2C(matrix(rnorm(90),ncol=9),matrix(rnorm(90),ncol=9))
Error in eval(expr, envir, enclos) : object "Pro" not found

Enter a frame number, or 0 to exit   

 1: AB2C(matrix(rnorm(90), ncol = 9), matrix(rnorm(90), ncol = 9))
 2: NextMethod("AB2C")
 3: AB2C.S(matrix(rnorm(90), ncol = 9), matrix(rnorm(90), ncol = 9))
 4: lm(t(cbind(a, b)) ~ Pro + syn + unk + Y + Nh + 0, offset = c(ac9aw,
ac9bw))
 5: eval(mf, parent.frame())
 6: eval(expr, envir, enclos)
 7: model.frame(formula = t(cbind(a, b)) ~ Pro + syn + unk + Y + Nh + 0,
offset = c(ac9a
 8: model.frame.default(formula = t(cbind(a, b)) ~ Pro + syn + unk + Y + Nh
+ 0, offset 
 9: eval(predvars, data, env)
10: eval(expr, envir, enclos)

Selection: 0

The function AB2C now sees ac9nw, and gives similar errors, related to other
hidden variables.


Duncan Murdoch-2 wrote:
> 
> On 5/25/2007 7:27 AM, Vladimir Eremeev wrote:
>> Thank you for the answer.
>> 
>> Here is everything.
>> 
>> ac9wl<-c(412,440,488,510,532,555,650,676,715)
>> ac9nw<-length(ac9wl)
>> 
>> AB2C <-function(a,b,model.type="S") {  
>>   nza<-dim(a)[1]
>>   nwa<-dim(a)[2]
>>   nzb<-dim(b)[1]
>>   nwb<-dim(b)[2]
>> 
>>   if(nza!=nzb || nwa!=ac9nw || nwb!=ac9nw) {
>>     warning('AB2C: Dimensions of the input matrices are invalid')
>>     return(NULL);
>>   }
>> 
>>  [ further calculations, they  do not use ac9nw ]  
>> }
> 
> 
> That would work, so my guess is that you aren't using that function.  If 
> you have a function named AB2C in your global environment, R will find 
> it before this one, and it may not be able to see the ac9nw variable.
> 
> Duncan Murdoch
> 
> 

-- 
View this message in context: http://www.nabble.com/private-variables-in-package.-tf3815306.html#a10801823
Sent from the R devel mailing list archive at Nabble.com.



More information about the R-devel mailing list