From simon.urbanek at r-project.org  Thu Dec 30 19:16:59 2010
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Thu, 30 Dec 2010 13:16:59 -0500
Subject: [Rd] key-value mapping in C inside R?
In-Reply-To: <146E8656-8D6A-4FFC-AB4B-BB0E8570F105@naufraghi.net>
References: <4D1C8012.7050403@naufraghi.net>
	<59A3C41D-ADC8-4B67-B83E-97E490B491FE@r-project.org>
	<146E8656-8D6A-4FFC-AB4B-BB0E8570F105@naufraghi.net>
Message-ID: <663226FA-CC47-45C3-9702-545FD347086E@r-project.org>


On Dec 30, 2010, at 11:25 AM, Matteo Bertini wrote:

> Il giorno 30/dic/2010, alle ore 16.03, Simon Urbanek ha scritto:
> 
>> On Dec 30, 2010, at 7:50 AM, Matteo Bertini wrote:
>> 
>>> I'm testing some modifications in arima.c.
>>> I've noticed that a big internal array of double (rbar) is usually sparse and I'd like to add an option to store it as key-value mapping.
>>> 
>>> Is there a library function or some other approach already used inside the R core for key-value mappings?
>>> 
>> 
>> environment created with hash=TRUE, e.g.:
>> e = new.env(TRUE, emptyenv())
>> e[["foo"]] = "bar"
>> 
>> You can even set "size" with the expected size if you know it in advance.
> 
> Interesting, but is it possible to use this from the C code?
> 

Sure, assignment:
void defineVar(SEXP symbol, SEXP value, SEXP rho)
retrieval:
SEXP findVarInFrame(SEXP rho, SEXP symbol)

so the above assignment would be in C
defineVar(install("foo"), mkString("bar"), env)
where env is the environment created above.

Cheers,
Simon



[Rd] key-value mapping in C inside R?
Simon Urbanek