From simon.urbanek at r-project.org  Fri May 10 14:37:41 2013
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Fri, 10 May 2013 08:37:41 -0400
Subject: [Rd] call R function from C code
In-Reply-To: <kmiev2$qj2$1@ger.gmane.org>
References: <kme57t$sca$1@ger.gmane.org>
	<2DC85D00-8F28-4EFA-BBE7-D5488B1DC894@r-project.org>
	<CADwqtCNZrAsF+j5NCqiAnqz7Go4eGSE5ctw0Hb0nYOjP6vswdA@mail.gmail.com>
	<kmiev2$qj2$1@ger.gmane.org>
Message-ID: <AD1B2862-34DB-42E4-BCDF-52FCEE80ACC5@r-project.org>

On May 10, 2013, at 5:34 AM, Matwey V. Kornilov wrote:

> 
> Thanks, It is what I was looking for. But now, I poorly understand environment conception. My initial C function in invoked from R (in some environment I suppose), how do I know this env, to provide it to eval()? Or, may I just make a clean env?
> 

It depends on where you want to evaluate it. R_GlobalEnv is the most common - mostly it acts as if you evaluated it on the console. If you want a particular namespace (e.g. myPackage), you can use R_FindNamespace(mkString("myPackage")) to find it.

Cheers,
Simon


> 
> 10.05.2013 00:13, Gabriel Becker ?????:
>> Matwey,
>> 
>> There are a number of ways to do this, but it depends on what exactly you
>> want. Do you want to execute a call to an actual R function from within C,
>> or do you want to directly call one of R's internal C functions (which may
>> work but is not future-safe unless it is part of the official API).
>> 
>> If its the first, see Martin Morgan's post here:
>> http://stackoverflow.com/questions/7457635/calling-r-function-from-c for
>> more detail about the approach I believe Simon is referring to. As for the
>> second, they are normal C functions, but I believe the consensus is that if
>> they aren't part of the API you are on your own figuring out how they work
>> (the source code is available for this of course).
>> 
>> Hope that helps,
>> ~G
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] call R function from C code
Simon Urbanek