I don't know why you are writing your own as.data.frame(), but if you
are using it only on certain types of objects, then I would recommend
you to define a *class specific* function. Using the S3/UseMethod
approach (different from S4/methods) this could look like:
x <- list(a=..., b=..., c=...) # Your data structure
class(x) <- c("MyClass") # Specifies that x is of class
"MyClass"
Then you can define an as.data.frame() that is only used on this class
and will leave all other data types unaffected:
as.data.frame.MyClass <- function(x, row.names=NULL, optional=FALSE) {
... # Do what you want here
}
Note the naming rule: <function>.<Class> <- function(<object>, ...)
When calling as.data.frame(x), the generic function as.data.frame() (the
one you've currently overwritten) will call the correct as.data.frame()
depending on the class of x, i.e. in this case as.data.frame.MyClass(x).
This method dispatching is done by the UseMethod() call.
Cheers
Henrik Bengtsson
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]] On Behalf Of Nunoo, Paa K
> Sent: den 8 januari 2003 09:23
> To: '[EMAIL PROTECTED]'
> Subject: [R] Namespace support?
>
>
> Hi,
> I have created an R package in which I implement my own version of the
> "as.dataframe" function. However when I load up my package into R, it
> seems to mask the original version of "as.data.frame". Is there to
> limit/control the scope of the "as.data.frame" function defined in the
> my package so that it does not interfere with the original function?
> Maybe by using namespaces in R?
>
> thanks
> PK
>
> ______________________________________________
> [EMAIL PROTECTED] mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/> r-help
>
>
______________________________________________
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help