From mlilback at stat.wvu.edu  Wed Oct 24 23:19:44 2012
From: mlilback at stat.wvu.edu (Mark Lilback)
Date: Wed, 24 Oct 2012 17:19:44 -0400
Subject: [Rd] Getting ordered factor levels from C
In-Reply-To: <47E3E25E-E4DE-451E-BC1F-71D0B857E64C@r-project.org>
References: <574D6602-6F6E-4EB3-99A6-6E1651A65D1B@stat.wvu.edu>
	<47E3E25E-E4DE-451E-BC1F-71D0B857E64C@r-project.org>
Message-ID: <D5E4B933-D6E2-4B1F-B720-DA59765AA6C0@stat.wvu.edu>

I was banging my head for an hour on this. I just pasted the code into an email and see that I was getting the contents of the SEXP for the factor, not the one returned by getAttrib. Sorry for the waste of time.


On Oct 24, 2012, at 4:16 PM, Simon Urbanek <simon.urbanek at r-project.org> wrote:

> 
> On Oct 24, 2012, at 2:14 PM, Mark Lilback wrote:
> 
>> I'm working on an R package in C and can't seem to get the same level information about a factor that the R console displays.
>> 
>> If I define a factor as:
>> 
>> lvls <- factor(c('red','blue','blue','green','red'), c('blue','green','red'), ordered=TRUE)
>> 
>> When I get the "levels" attribute in C, I get back the the first vector, not the second.
> 
> What are you using in C? AFAICS it works just fine:
> 
>> f=cfunction(c(foo="factor"), "return getAttrib(foo, R_LevelsSymbol);")
>> f(lvls)
> [1] "blue"  "green" "red"  
> 



-- 
Mark Lilback
West Virginia University Department of Statistics
mlilback at stat.wvu.edu



[Rd] Getting ordered factor levels from C
Mark Lilback