From murdoch at stats.uwo.ca  Wed May 23 19:36:12 2007
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Wed, 23 May 2007 13:36:12 -0400
Subject: [Rd] package: 'inline' to inline C or C++ code in R functions
In-Reply-To: <46546348.5070605@ebi.ac.uk>
References: <46532F64.9030203@ebi.ac.uk> <46534A0A.6050508@stats.uwo.ca>
	<46546348.5070605@ebi.ac.uk>
Message-ID: <46547B8C.80508@stats.uwo.ca>

On 5/23/2007 11:52 AM, Oleg Sklyar wrote:
> Dear all,
> 
> following the earlier discussion, I've made a couple of changes to
> 'inline' (http://www.ebi.ac.uk/~osklyar/inline). As announced before the
> idea of the package is to enable inlining C or C++ code in R functions
> using only R sources. The changes include:
> 
> - it is possible to select between C and C++
> - it is possible to declare a standard R function calling a C/C++
>   routine or an S4 method with a fixed signature
> - setCMethod accepts single of multiple method signatures in a list, all
>   put in one shared object
> - readline syntax is used in the example for a multiline C++ source :)
> 
> Thanks Duncan, Simon and Deepayan for useful comments!
> 
> Not tested on Windows, I would be thankful if somebody could do it.

It doesn't quite work there.  There are two problems: the test for 
windows should be based on .Platform$OS.type, and R CMD SHLIB expects 
filenames with Unix-style path separators.  I've attached a patch.

Other suggestions:  instead of relying on the filename for lookup when 
calling the compiled code, you might want to use getNativeSymbolInfo to 
obtain it right after compiling.  This can be used as the name argument 
in .Call, but will avoid doing another lookup in the DLL, possibly 
finding a name clash.

You were asking how to handle automatic unloading:  I haven't done this 
myself, but I think RODBC does something similar to close database 
connections.

Something else you might want to think about:  if someone saves one of 
your cfunction results, you may need to recompile it when they reload.

Thanks for writing this, it's looking really nice.

Duncan Murdoch
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch
Url: https://stat.ethz.ch/pipermail/r-devel/attachments/20070523/244fa858/attachment.pl 


[Rd] package: 'inline' to inline C or C++ code in R functions
Duncan Murdoch