I'd be happy to follow the naming convention for generics when handling
named arrays.
On Monday, October 27, 2014 11:17:47 AM UTC-4, David van Leeuwen wrote:
>
> Hi,
>
> There is a package NamedArray that attempts to make it possible to work
> with named indices and dimensions in native Julia arrays, just like you are
> used to in R. There is no interface to Rif.jl, though. Would this be a
> useful extension?
>
> ---david
>
> On Sunday, October 26, 2014 11:01:51 PM UTC+1, lgautier wrote:
>>
>> Currently the way to do is to explicitly call the R-level setter:
>>
>> x = Rif.R("names<-")(x, Rif.cR("A", "B", "C"))
>>
>>
>> However, as of today commit the C-level is exposed and a way that is
>> looking a little more like native Julia.
>> (I'll do a pull request so this is part of the released package soon).
>>
>> The unit-tests are for vectors, and should be explict:
>> https://github.com/lgautier/Rif.jl/blob/master/test/vectors.jl#L57
>>
>> ```julia
>> # The C API for R has specialized MACRO for names getrnames/setrnames
>> # exposes it
>> vi2 = Int32[1,2,3]
>> rvi2 = Rif.RArray{Int32,1}(vi2)
>> @test isequal(None, Rif.getrnames(rvi2))
>> Rif.setrnames!(rvi2, Rif.RArray{ASCIIString,1}(ASCIIString["a", "b",
>> "c"]))
>> @test isequal("a", Rif.getrnames(rvi2)[1])
>> @test isequal("b", Rif.getrnames(rvi2)[2])
>> @test isequal("c", Rif.getrnames(rvi2)[3])
>>
>> # setAttr/getAttr will be equivalent
>> vi2 = Int32[1,2,3]
>> rvi2 = Rif.RArray{Int32,1}(vi2)
>> @test_throws ErrorException Rif.getAttr(rvi2, "names")
>> Rif.setAttr!(rvi2, "names",
>> Rif.RArray{ASCIIString,1}(ASCIIString["a", "b", "c"]))
>> @test isequal("a", Rif.getAttr(rvi2, "names")[1])
>> @test isequal("a", Rif.getrnames(rvi2)[1])
>> @test isequal("b", Rif.getAttr(rvi2, "names")[2])
>> @test isequal("b", Rif.getrnames(rvi2)[2])
>> @test isequal("c", Rif.getAttr(rvi2, "names")[3])
>> @test isequal("c", Rif.getrnames(rvi2)[3])
>> ```
>>
>> On Saturday, October 25, 2014 12:38:10 PM UTC-4, [email protected]
>> wrote:
>>>
>>> In R, we can assign names for a variable as:
>>> > x<-c(1,2,3)
>>> > names(x)=c("A","B","C")
>>> > x
>>> A B C
>>> 1 2 3
>>>
>>> In Julia, I can create a RArray by
>>> x=Rif.cR([1,2,3])
>>> But anyone know how to assign the "names" to this RArray variable in
>>> Julia?
>>>
>>