I turns out that:

1- the error message is wrong (fixed in master)
2- it should be Rif.R("`names<-`")
3- better to open an issue on github than post on the list
4- the alternative (getrnames/setrnames) should now be the in latest 
release of Rif. Just update.



On Wednesday, October 29, 2014 5:15:09 AM UTC-4, xiong...@gmail.com wrote:
>
> I'm afraid the Rif.R("names<-") is not working.
>
> julia> Rif.initr()
> Using R_HOME=/home/Mine/programs/Rstat/R-3.1.1
> 0
>
> julia> Rif.R("names<-")
> ERROR: R is not initialized
>  in parseR at /home/JXiong/.julia/v0.4/Rif/src/Rif.jl:251
>  in R at /home/JXiong/.julia/v0.4/Rif/src/Rif.jl:277
>
>
>
> 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, xiong...@gmail.com 
>> 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?
>>>
>>

Reply via email to