-----Oprindelig meddelelse-----
Fra: Jens Henrik Badsberg
Sendt: 16. marts 2004 11:37
Til: 'r-help@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@label)
setGeneric("label<-", function(x, value) standardGeneric("label<-"))
setReplaceMethod("label", "NodeProto", function(x, value) {
x@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.
-------------- 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]