[Rd] VS: Documentation on how to put classes and methods in packages with namespace?

Jens Henrik Badsberg JensHenrik.Badsberg at agrsci.dk
Tue Mar 16 11:38:29 MET 2004



>  -----Oprindelig meddelelse-----
> Fra: 	Jens Henrik Badsberg  
> Sendt:	16. marts 2004 11:37
> Til:	'r-help at stat.math.ethz.ch'
> Emne:	Documentation on how to put classes and methods in packages with namespace?
> 
> 
>  Documentation on how to put classes and methods in packages with namespace?
> 
>  How should I define my classes and methods in "dynamicGraph"???
> 
>  (That is - Can some one point me to the documentation on
>  how to put classes and methods in packages with a namespace? )
> 
>  Currently it is done by the code below.
> 
>  This gives problems, when a workspace with a "dynmaicGraph" is restored:
> 
>  1. run:
> 
>      local({a <- CRAN.packages()
>      install.packages(select.list(a[,1],,TRUE), .libPaths()[1], available=a)})
>      search()
>      library(dynamicGraph)
>      a <- DynamicGraph(1:10)
>      search()
>      ls(pos=3, all.names=TRUE)
>      history()
>      q(save="yes")
> 
>  2. run:
> 
>      search()
>      ls()
>      library(dynamicGraph)
>      search()
>      ls(pos=3, all.names=TRUE)
>      b <- DynamicGraph(1:10)
>      history()
> 
>  The classes and methods of dynamicGraph is not assigned, see the attached "run2.txt",
>  and compare with the list of the objects of dynamicGraph in "run1.txt".
> 
>  I have experimented with the argument "where" to setClass, etc., see the attached
>  "onLoad.R".
> 
>  Regards,
> 
>  Jens Henrik Badsberg
> 
> 
> 
> ".onAttach" <-
> function (lib, pkg) 
> {
>     require(tcltk)
> }
> ".onLoad" <-
> function (lib, pkg) 
> {
>     .onLoad.dynamicGraph()
> }
> ".onLoad.dynamicGraph" <-
> function () 
> {
>     library(methods)
>     setClass("GraphLatticeProto", representation(vertices = "list", 
>         blocks = "list", blockTree = "list", graphs = "list"))
>     setClass("CanvasProto", representation(top = "tkwin", canvas = "tkwin", 
>         tags = "list", id = "numeric", visibleVertices = "numeric", 
>         graphEdges = "list", blockEdges = "list", factorVertices = "list", 
>         factorEdges = "list"))
>     setClass("NodeProto", representation(color = "character", 
>         label = "character", label.position = "numeric"), prototype(color = "black", 
>         label = "Label", label.position = c(0, 0, 0)))
> 
>     ### .... Many lines deleted ....
> 
>     if (!isGeneric("label")) {
>         if (is.function("label")) 
>             fun <- label
>         else fun <- function(object) standardGeneric("label")
>         setGeneric("label", fun)
>     }
>     setMethod("label", "NodeProto", function(object) object at label)
>     setGeneric("label<-", function(x, value) standardGeneric("label<-"))
>     setReplaceMethod("label", "NodeProto", function(x, value) {
>         x at label <- value
>         x
>     })
> 
>     ### .... Many lines deleted ....
> 
> }
> >  <<run1.txt>> > >  <<run2.txt>> > >  <<onLoad.R>> 
-------------- next part --------------


local({a <- CRAN.packages()
install.packages(select.list(a[,1],,TRUE), .libPaths()[1], available=a)})
search()
library(dynamicGraph)
a <- DynamicGraph(1:10)
search()
ls(pos=3, all.names=TRUE)
history()
q(save="yes")



R : Copyright 2003, The R Foundation for Statistical Computing
Version 1.8.1  (2003-11-21), ISBN 3-900051-00-3

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 in publications.

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

> local({a <- CRAN.packages()
+ install.packages(select.list(a[,1],,TRUE), .libPaths()[1], available=a)})
trying URL `http://cran.r-project.org/bin/windows/contrib/1.8/PACKAGES'
Content type `text/plain; charset=iso-8859-1' length 16234 bytes
opened URL
downloaded 15Kb

trying URL `http://cran.r-project.org/bin/windows/contrib/1.8/dynamicGraph_0.1.5.9.9.8.8.zip'
Content type `application/zip' length 347067 bytes
opened URL
downloaded 338Kb

package  dynamicGraph  successfully unpacked and MD5 sums checked

Delete downloaded files (y/N)? y

updating HTML package descriptions
> search()
[1] ".GlobalEnv"      "package:methods" "package:ctest"   "package:mva"    
[5] "package:modreg"  "package:nls"     "package:ts"      "Autoloads"      
[9] "package:base"   
> library(dynamicGraph)
Loading required package: tcltk 
> a <- DynamicGraph(1:10)
> search()
 [1] ".GlobalEnv"           "package:tcltk"        "package:dynamicGraph"
 [4] "package:methods"      "package:ctest"        "package:mva"         
 [7] "package:modreg"       "package:nls"          "package:ts"          
[10] "Autoloads"            "package:base"        
> ls(pos=3, all.names=TRUE)
  [1] ".__C__BlockEdgeProto"                   ".__C__BlockProto"                      
  [3] ".__C__CanvasProto"                      ".__C__ContinuousVertexProto"           
  [5] ".__C__defaultModelObjectProto"          ".__C__defaultTestObjectProto"          
  [7] ".__C__DiscreteGeneratorProto"           ".__C__DiscreteVertexProto"             
  [9] ".__C__EdgeProto"                        ".__C__FactorEdgeProto"                 
 [11] ".__C__FactorVertexProto"                ".__C__GeneratorProto"                  
 [13] ".__C__GraphLatticeProto"                ".__C__LinearGeneratorProto"            
 [15] ".__C__NodeProto"                        ".__C__OrdinalVertexProto"              
 [17] ".__C__QuadraticGeneratorProto"          ".__C__VertexEdgeProto"                 
 [19] ".__C__VertexProto"                      ".__M__addToPopups:dynamicGraph"        
 [21] ".__M__ancestors:dynamicGraph"           ".__M__ancestors<-:dynamicGraph"        
 [23] ".__M__color:dynamicGraph"               ".__M__color<-:dynamicGraph"            
 [25] ".__M__Colors:dynamicGraph"              ".__M__Colors<-:dynamicGraph"           
 [27] ".__M__descendants:dynamicGraph"         ".__M__descendants<-:dynamicGraph"      
 [29] ".__M__draw:dynamicGraph"                ".__M__edgeLabel:dynamicGraph"          
 [31] ".__M__edgeLabel<-:dynamicGraph"         ".__M__edgeWidth:dynamicGraph"          
 [33] ".__M__edgeWidth<-:dynamicGraph"         ".__M__index:dynamicGraph"              
 [35] ".__M__index<-:dynamicGraph"             ".__M__Indices:dynamicGraph"            
 [37] ".__M__label:dynamicGraph"               ".__M__label<-:dynamicGraph"            
 [39] ".__M__labelOfEdge:dynamicGraph"         ".__M__labelOfEdge<-:dynamicGraph"      
 [41] ".__M__labelPosition:dynamicGraph"       ".__M__labelPosition<-:dynamicGraph"    
 [43] ".__M__LabelPositions:dynamicGraph"      ".__M__LabelPositions<-:dynamicGraph"   
 [45] ".__M__Labels:dynamicGraph"              ".__M__Labels<-:dynamicGraph"           
 [47] ".__M__name:dynamicGraph"                ".__M__name<-:dynamicGraph"             
 [49] ".__M__Names:dynamicGraph"               ".__M__Names<-:dynamicGraph"            
 [51] ".__M__NodeAncestors:dynamicGraph"       ".__M__NodeAncestors<-:dynamicGraph"    
 [53] ".__M__NodeDescendants:dynamicGraph"     ".__M__NodeDescendants<-:dynamicGraph"  
 [55] ".__M__nodeIndices:dynamicGraph"         ".__M__NodeIndices:dynamicGraph"        
 [57] ".__M__nodeIndices<-:dynamicGraph"       ".__M__nodeIndicesOfEdge:dynamicGraph"  
 [59] ".__M__nodeIndicesOfEdge<-:dynamicGraph" ".__M__NodeTypes:dynamicGraph"          
 [61] ".__M__nodeTypesOfEdge:dynamicGraph"     ".__M__oriented:dynamicGraph"           
 [63] ".__M__Oriented:dynamicGraph"            ".__M__oriented<-:dynamicGraph"         
 [65] ".__M__Oriented<-:dynamicGraph"          ".__M__position:dynamicGraph"           
 [67] ".__M__position<-:dynamicGraph"          ".__M__Positions:dynamicGraph"          
 [69] ".__M__Positions<-:dynamicGraph"         ".__M__Strata:dynamicGraph"             
 [71] ".__M__Strata<-:dynamicGraph"            ".__M__stratum:dynamicGraph"            
 [73] ".__M__stratum<-:dynamicGraph"           ".__M__visible:dynamicGraph"            
 [75] ".__M__Visible:dynamicGraph"             ".__M__visible<-:dynamicGraph"          
 [77] ".__M__Visible<-:dynamicGraph"           ".__M__width:dynamicGraph"              
 [79] ".__M__width<-:dynamicGraph"             ".__M__widthOfEdge:dynamicGraph"        
 [81] ".__M__widthOfEdge<-:dynamicGraph"       ".__M__Widths:dynamicGraph"             
 [83] ".__M__Widths<-:dynamicGraph"            ".onLoad.dynamicGraph"                  
 [85] ".onLoad.dynamicGraphInterface"          "addToPopups"                           
 [87] "ancestors"                              "ancestors<-"                           
 [89] "blockTreeToList"                        "color"                                 
 [91] "color<-"                                "Colors"                                
 [93] "Colors<-"                               "descendants"                           
 [95] "descendants<-"                          "draw"                                  
 [97] "DynamicGraph"                           "dynamicGraphMain"                      
 [99] "edgeLabel"                              "edgeLabel<-"                           
[101] "edgeWidth"                              "edgeWidth<-"                           
[103] "index"                                  "index<-"                               
[105] "Indices"                                "label"                                 
[107] "label<-"                                "labelOfEdge"                           
[109] "labelOfEdge<-"                          "labelPosition"                         
[111] "labelPosition<-"                        "LabelPositions"                        
[113] "LabelPositions<-"                       "Labels"                                
[115] "Labels<-"                               "modalDialog"                           
[117] "name"                                   "name<-"                                
[119] "Names"                                  "Names<-"                               
[121] "nameToVertexIndex"                      "newBlock"                              
[123] "newBlockEdge"                           "newDefaultModelObject"                 
[125] "newDefaultTestObject"                   "newFactor"                             
[127] "newFactorEdge"                          "newVertex"                             
[129] "newVertexEdge"                          "NodeAncestors"                         
[131] "NodeAncestors<-"                        "NodeDescendants"                       
[133] "NodeDescendants<-"                      "nodeIndices"                           
[135] "NodeIndices"                            "nodeIndices<-"                         
[137] "nodeIndicesOfEdge"                      "nodeIndicesOfEdge<-"                   
[139] "NodeTypes"                              "nodeTypesOfEdge"                       
[141] "oriented"                               "Oriented"                              
[143] "oriented<-"                             "Oriented<-"                            
[145] "position"                               "position<-"                            
[147] "Positions"                              "Positions<-"                           
[149] "returnBlockEdgeList"                    "returnEdgeList"                        
[151] "returnFactorEdgeList"                   "returnFactorVerticesAndEdges"          
[153] "returnVertexList"                       "setBlocks"                             
[155] "setTreeBlocks"                          "Strata"                                
[157] "Strata<-"                               "stratum"                               
[159] "stratum<-"                              "validFactorClasses"                    
[161] "validVertexClasses"                     "visible"                               
[163] "Visible"                                "visible<-"                             
[165] "Visible<-"                              "width"                                 
[167] "width<-"                                "widthOfEdge"                           
[169] "widthOfEdge<-"                          "Widths"                                
[171] "Widths<-"                              
> history()
> q(save="yes")

-------------- next part --------------
search()
ls()
library(dynamicGraph)
search()
ls(pos=3, all.names=TRUE)
b <- DynamicGraph(1:10)
history()


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

[Previously saved workspace restored]

> search()
[1] ".GlobalEnv"      "package:ctest"   "package:mva"     "package:modreg"  "package:nls"    
[6] "package:ts"      "package:methods" "Autoloads"       "package:base"   
> ls()
[1] "a"
> library(dynamicGraph)
Loading required package: tcltk 
> search()
 [1] ".GlobalEnv"           "package:tcltk"        "package:dynamicGraph"
 [4] "package:ctest"        "package:mva"          "package:modreg"      
 [7] "package:nls"          "package:ts"           "package:methods"     
[10] "Autoloads"            "package:base"        
> ls(pos=3, all.names=TRUE)
 [1] ".onLoad.dynamicGraph"          ".onLoad.dynamicGraphInterface"
 [3] "blockTreeToList"               "DynamicGraph"                 
 [5] "dynamicGraphMain"              "modalDialog"                  
 [7] "nameToVertexIndex"             "newBlock"                     
 [9] "newBlockEdge"                  "newDefaultModelObject"        
[11] "newDefaultTestObject"          "newFactor"                    
[13] "newFactorEdge"                 "newVertex"                    
[15] "newVertexEdge"                 "returnBlockEdgeList"          
[17] "returnEdgeList"                "returnFactorEdgeList"         
[19] "returnFactorVerticesAndEdges"  "returnVertexList"             
[21] "setBlocks"                     "setTreeBlocks"                
[23] "validFactorClasses"            "validVertexClasses"           
> b <- DynamicGraph(1:10)
Error in getClass(superClass) : "NodeProto" is not a defined class
> history()
> q()


More information about the R-devel mailing list