From simon.urbanek at r-project.org  Tue Mar 17 22:49:33 2009
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Tue, 17 Mar 2009 17:49:33 -0400
Subject: [Rd] question on "row.names" attribute of dataframe when called
	from a compiled package
In-Reply-To: <8ec76080903171345h98a17efx67aed1f861d0d271@mail.gmail.com>
References: <8ec76080903171345h98a17efx67aed1f861d0d271@mail.gmail.com>
Message-ID: <C6DE79D9-41FF-40BA-AD60-0E93E0F0644D@r-project.org>


On Mar 17, 2009, at 16:45 , Whit Armstrong wrote:

> Why does the following show a class attribute of "character" when  
> using the interpreter:
>
> x <- data.frame(hat=1:10)
> class(rownames(x))  ## returns [1] "character"
>
> but when called from c/cpp, the rownames attribute has no class  
> attribute

Note the difference between class("foo") and attr("foo", "class") -  
some classes are implicit.


> , and is in fact a vector of INTSXP?
>

Because the internal representation of automatic row names is c(NA, - 
dim(d)[1]) where d is the data frame. This is not exposed at the R  
level, though, since it's an implementation optimization.


>> .Call("print_class_of_rownames", x, package = "test")
> length(x): 10
> TYPEOF(x): 13
> R_ClassSymbol is null.
> NULL
>>
>
> is this the intended behaviour?
>

Yes - it saves a lot of space when using large datasets with automatic  
names.

Cheers,
Simon


> -Whit
>
>
> here is my test code:
>
> SEXP print_class_of_rownames(SEXP dataframe_sexp) {
>  SEXP x = getAttrib(dataframe_sexp,install("row.names"));
>  cout << "length(x): " << length(x) << endl;
>  cout << "TYPEOF(x): " << TYPEOF(x) << endl;
>  if(getAttrib(x, R_ClassSymbol)==R_NilValue) {
>    cout << "R_ClassSymbol is null." << endl;
>  } else {
>    cout << "R_ClassSymbol is a good value." << endl;
>  }
>  return R_NilValue;
> }
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>



[Rd] question on "row.names" attribute of dataframe when called from a compiled package
Simon Urbanek