Fg,
This is not really an r-devel question. It is more appropriate for r-help
as far as I know. Please ask questions like it there in the future.
Anyway, my understanding is that the type of an object has to do with how
it is stored internally, whereas the class has to do with how it is
dispatched on. For example, in the S3 system , it is entirely reasonable to
do the following:
> x = 1:10
> class(x) = "myspecialint"
> x
[1] 1 2 3 4 5 6 7 8 9 10
attr(,"class")
[1] "myspecialint"> print.myspecialint = function(x, ...) print(mean(x))
> print(x)
[1] 5.5> typeof(x)
[1] "integer"
As you can see, changing the "class" of x did not change how it was
stored
internally.
Another canonical example is the matrix class. Matrices in R are stored as
vectors of the relevant type, with additional attributes indicating their
dimension. So while there is a matrix class, there is no matrix type.
> x = matrix(1:10, nrow=2)
> x
[,1] [,2] [,3] [,4] [,5]
[1,] 1 3 5 7 9
[2,] 2 4 6 8 10> typeof(x)
[1] "integer"
HTH,
~G
On Tue, Dec 24, 2013 at 12:26 PM, Fg Nu <fgnu32@yahoo.com> wrote:
>
>
>
> I came across the distinction between the name of an object and the name
> of the class that it belongs to in an oblique way again today, which made
> me question my acceptance that it would be natural for them to differ.
>
> I asked a question on SO here:
>
>
http://stackoverflow.com/questions/20762559/why-is-the-name-of-an-object-type-different-from-the-name-of-the-class-it-belong
>
> I wonder if anyone on the R-Devel list has a better explanation for why
> the class name of an object and the object type name of an object should
> differ?
>
> Happy holidays,
>
> fg
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
--
Gabriel Becker
Graduate Student
Statistics Department
University of California, Davis
[[alternative HTML version deleted]]