[R] On-demand importing of a package

Gabor Grothendieck ggrothendieck at gmail.com
Fri Nov 25 22:25:59 CET 2011


On Fri, Nov 25, 2011 at 2:47 PM, Jakson Alves de Aquino
<jalvesaq at gmail.com> wrote:
> On Fri, Nov 25, 2011 at 2:40 PM, Gabor Grothendieck
> <ggrothendieck at gmail.com> wrote:
>>> I think that the following procedure has the result that you want:
>>>
>>> Put in the DESCRIPTION file:
>>>
>>> Imports: RSQLite
>>>
>>> And in the R code write something like:
>>>
>>> RSQLite::AnRSQLiteFunction()
>>
>> I had been thinking of using Imports in DESCRIPTION but was concerned
>> that that would put RSQLite objects ahead of everything else on
>> sqldf's search path even when not wanted but I gather you are
>> intending that Imports be used in DESCRIPTION: but _not_ in the
>> NAMESPACE file.  I think that that would likely work. I will test it
>> out to be sure. What I would probably want to do is to require()
>> RSQLite in case the user wants to mix sqldf and RSQLite calls and I
>> will check whether the check procedure allows that if the package is
>> only named in Imports but, if not, it might be sufficient to put
>> RSQLite in both Imports and Suggests.  Thanks.
>
> I have done this with the 'descr' package. It wasn't necessary to put
> the imported packages in two places, only in the "Imports" field. This
> was enough to make R install all dependencies but not load then along
> with 'descr'.

I just tried it but I wanted to require() RSQLite so that the user can
access its facilities as well and although putting it just in Imports
does work the check complains about requiring a package that has not
been declared unless I put it in Suggests as well.  If I don't do a
require() then it would not be necessary to put it in Suggests so
there seems to be a slight difference between descr and sqldf.


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list