[Rd] R package compilation: files in src directory should be ignored if C library is not available

Uwe Ligges ligges at statistik.tu-dortmund.de
Fri Aug 17 13:51:35 CEST 2012



On 17.08.2012 13:49, Cule, Erika wrote:
> But will package compilation fail if GSL is not installed?

No, not this way: since the gsl package can be in the Suggests now 
(rather than the Depends).

Best,
Uwe Ligges


>
> (There are files in the src directory that are needed for the code to run)
>
> On 17 Aug 2012, at 12:47, Uwe Ligges wrote:
>
>>
>>
>> On 17.08.2012 13:44, Cule, Erika wrote:
>>> Thanks Uwe
>>>
>>> I am not quite sure I understand.
>>>
>>> To clarify, do you mean writing my R functions as something like:
>>>
>>> functionRequiringGsl <- function(arg1, arg2)
>>> {
>>> 	if(require(gsl))
>>> 	{
>>> 		## Some functions that use GSL
>>> 		## called using .C()
>>> 	} else {
>>> 		stop("GSL not available")
>>> 	}
>>> }
>>>
>>> If so, I still don't understand what happens when I compile the package if GSL is not installed on the computer, as there will still be C code in the src directory.
>>
>> Yes, I meant such a function. If GSL is not available, this function will give an ERROR, but the rest of the package works.
>>
>> Uwe Ligges
>>
>>
>>> Thanks again
>>>
>>> Erika
>>>
>>>
>>> On 17 Aug 2012, at 12:35, Uwe Ligges wrote:
>>>
>>>>
>>>>
>>>> On 17.08.2012 11:11, Cule, Erika wrote:
>>>>> I have written an R package which contains C source code (in the directory pkg/src).
>>>>>
>>>>> Only a subset of the functions in the pkg/R directory contain a .C() call to the functions in the pkg/src directory. The rest of the package will still work and be useful without the functions containing a .C() call.
>>>>>
>>>>> To compile the code in pkg/src requires the GSL library. This is detailed in the SystemRequirements line of the DESCRIPTION file and the Makevars file directs the compiler to LIB_GSL.
>>>>>
>>>>> At what stage will installation fail for the end user if they don't have GSL installed?
>>>>>
>>>>> I have used Autoconf and configure, following the example in 1.2 of "Writing R Extensions" and the configure.ac file in the R package gsl, to detect whether the GSL library is installed on the computer and disable the R functions if the GSL library is not found (by using a TRUE/FALSE pattern substitution, as in the example in "Writing R Extensions"). If GSL is not available, will the package now install on another users machine with these functions disabled? Or upon installation will the installer try to install the code in pkg/src and fail because the libraries are not available?
>>>>
>>>> Yes, you have to work around the installation steps that compile and link your C sources and then the call to dynload the shared library in R.
>>>>
>>>> It is porbably easier to use the gsl library via the gsl package, given it ptovides the gsl functionality you are using. In that case, you just need to suggest the gsl package an load it for the one function on demand only.
>>>>
>>>> Best,
>>>> Uwe ligges
>>>>
>>>>
>>>>> Is there a practical way to test this? Both of the computers I have access to have GSL available, and installation works whether I set HAVE_GSL=TRUE or HAVE_GSL=FALSE (although in the latter case the corresponding R functions are disabled).
>>>>>
>>>>> I hope that this is clear, and am happy to post my code if it would be useful.
>>>>>
>>>>> Many thanks in advance.
>>>>>
>>>>> Erika
>>>>>
>>>>> ---
>>>>>
>>>>> Erika Cule
>>>>> PhD student in Statistical Genetics
>>>>> Imperial College London
>>>>> Department of Epidemiology and Public Health
>>>>> erika.cule05 at imperial.ac.uk
>>>>> http://occamstypewriter.org/erikacule/
>>>>>
>>>>> ______________________________________________
>>>>> R-devel at r-project.org mailing list
>>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>>
>>>
>



More information about the R-devel mailing list