Hello,

I too would expected NextMethod to work but the following seems to be simpler.
"names" is an attribute, so should be accessible with attr.



names.pm = function(p) {
  attr(p, "names")
}

p = data.frame(x=1:3, coeff=1)
class(p) = c("pm", class(p));

names(p)
#[1] "x"     "coeff"



Hope this helps,

Rui Barradas

Às 18:35 de 03/11/21, Leonard Mada via R-help escreveu:
Dear List members,


Is there a way to access the default names() function?


I tried the following:

# Multi-variable polynomial

p = data.frame(x=1:3, coeff=1)

class(p) = c("pm", class(p));


names.pm = function(p) {
# .Primitive("names")(p) # does NOT function
# .Internal("names")(p) # does NOT function
# nms = names.default(p) # does NOT exist
# nms = names.data.frame(p) # does NOT exist
# nms = names(p); # obvious infinite recursion;
nms = names(unclass(p));
}


Alternatively:

Would it be better to use dimnames.pm instead of names.pm?

I am not fully aware of the advantages and disadvantages of dimnames vs names.


Sincerely,


Leonard

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to