S3 class names: what is allowed?

Are there any restrictions on S3 class names? For example, are spaces allowed in a name? I see that there is a class "data.frame" in the data frame, and not a "data frame". If there is no formal restriction, are there potential problems with spaces in the name? I just don’t encounter anything other than the main modes, so I’m sure that those of you who have more experience will find out.

+6
source share
2 answers

It does not look like a lot of restrictions. Check out this monster:

`plot.44 !@ #$%^&` <- function(x) { plot(rnorm(x), pch=16, col="red", main = "But why would you want to do this??") } dat <- 55 class(dat) <- "44 !@ #$%^&" plot(dat) 

One of the reasons not to put spaces in the class name is that it is a little harder to directly call methods for this class.

 plot.44 !@ #$%^&(100) # This doesn't work `plot.44 !@ #$%^&`(100) # You have to do this instead 
+6
source

Spaces allowed:

 test = 1 class( test ) = c( class( test ) , "My Class" ) 

Not sure about other restrictions or consequences of having special characters in class names. Of course, the presence of spaces / special characters in class names is not ordinary (not only R, but also other languages). I suggest avoiding this.

+2
source

Source: https://habr.com/ru/post/899648/


All Articles