[R] Documentation on how to put classes and methods in packages with namespace?
Jens Henrik Badsberg
JensHenrik.Badsberg at agrsci.dk
Tue Mar 16 11:37:02 CET 2004
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 --------------
An embedded and charset-unspecified text was scrubbed...
Name: run1.txt
Url: https://stat.ethz.ch/pipermail/r-help/attachments/20040316/9729437f/run1.txt
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: run2.txt
Url: https://stat.ethz.ch/pipermail/r-help/attachments/20040316/9729437f/run2.txt
More information about the R-help
mailing list