Are there any restrictions on the names of S3 classes? For instance, are spaces allowed in the name? I see that data frames have a class of "data.frame" not "data frame". If there is not a formal restriction, are there potential problems with having spaces in the name? I just don't run into anything other than the basic modes so I'm sure those of you with more experience will know.
Doesn't look there are many restrictions at all. Check out this monstrosity:
`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 reason not to put spaces into a class name is that it makes it a bit trickier to directly call methods for that class.
plot.44 !@#$%^&(100) # This doesn't work
`plot.44 !@#$%^&`(100) # You have to do this instead
Spaces are allowed:
test = 1
class( test ) = c( class( test ) , "My Class" )
Not sure about other restrictions or consequences of having special characters in class names. Certainly having spaces/special characters in class names is not conventional (not just R, but other languages). I suggest avoiding that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With