[Rd] about integration of a library into package creation

Duncan Murdoch murdoch at stats.uwo.ca
Tue Jun 13 13:58:20 CEST 2006


Nicolas Turenne wrote:
> it works fine if i avoid importFrom directive
> thank you very much
>
> i have a last question
> the R source code cannot admit gloval variable ? because i have global 
> variables
> and i get the following message after loading my package by the command 
> 'library(svcR)':
>
> The following object(s) are masked _by_ .GlobalEnv : findModelCluster
>   
R has a reasonably sophisticated scheme for setting the scope of 
variables.  Variables in the base package are "global" for most 
purposes.  Variables in the user workspace are global in the sense that 
they are visible to most functions.

What the error message means is that you have two variables named 
findModelCluster, in two locations:  one in the user workspace 
(.GlobalEnv), and another in your package.  Since you are using a 
namespace, your package code will see your copy, but most other users 
will see the .GlobalEnv copy.

If this isn't enough to clear things up, you should describe what you 
want to do, rather than how you want to do it.  Terms like "global 
variables" from other languages don't always make sense in R.

Duncan Murdoch
>
> thank for help
>
> --
> Nicolas
>
>
> Duncan Murdoch a écrit :
>
>   
>> Nicolas Turenne wrote:
>>
>>     
>>> i follow your recommendation writing this :
>>> in the description file
>>> Depends: R (>= 2.3), quadprog, ade4, spdep
>>> Imports: quadprog, ade4, spdep
>>>
>>> in the namespace file
>>> useDynLib(quadprog)
>>> useDynLib(spdep)
>>> useDynLib(ade4)
>>> importFrom("ade4", "dist.dudi")
>>> importFrom("quadprog", "solve.QP")
>>> importFrom("ade4", "mstree")
>>> importFrom("ade4", "neig2mat")
>>> importFrom("ade4", "dist.dudi")
>>> importFrom("ade4", "dudi.pca")
>>> importFrom("ade4", "dudi.coa")
>>> importFrom("spdep", "knearneigh")
>>>   
>>>       
>> I think you are doing too much!
>> 1.  You should not use "useDynLib" for the DLL from another package.  
>> Let the other package load its own DLL.
>>
>> 2.  If you declare that your package Depends on the other packages, 
>> then they will be loaded and attached, and the importFrom lines will 
>> not be needed.
>> "Import"ing and "Depend"ing are similar but not identical concepts.  
>> Routines that are imported are available to your package *before* the 
>> global environment (i.e. user workspace).  Routines that are in 
>> packages attached by Depends come after the global environment, so 
>> there's a possibility that the user could create a routine named e.g. 
>> "mstree", and your code would use that version, rather than the one 
>> from ade4.  So normally "Imports" is better than "Depends".
>>
>> However, it appears that you can only import packages that have a 
>> namespace.  (I was unaware of this restriction; perhaps it's not 
>> really true, and the error message means something else.)
>>
>> So you can probably get rid of the error message by using only 
>> Depends, but you may want to keep the Imports from packages other than 
>> quadprog.
>>
>> Duncan Murdoch
>>
>>     
>>> and the result of compiling is :
>>>   preparing package svcR for lazy loading
>>> Erreur dans loadNamespace(ns, lib.loc) : le package 'quadprog' n'a 
>>> pas d'espace de noms
>>> Exécution arrêtée
>>> make: *** [lazyload] Error 1
>>> *** Installation of svcR failed ***
>>>
>>> it says that quadprog has not a namespace
>>> perhaps it is due to location of quadprog.dll
>>> i have put it into inst/src directory
>>>
>>> thank for help
>>>
>>> Nicolas
>>>
>>> Uwe Ligges a écrit :
>>>
>>>  
>>>
>>>       
>>>> Nicolas Turenne wrote:
>>>>
>>>>    
>>>>
>>>>         
>>>>> your answer is correct after checking some doc
>>>>> but examples are rare
>>>>>
>>>>> when i write in the description file
>>>>> Depends: R (>= 2.3), quadprog, ade4, spdep
>>>>> and in the namespcae file
>>>>>
>>>>> useDynLib(quadprog)
>>>>> useDynLib(spdep)
>>>>> useDynLib(ade4)
>>>>> importFrom("dist.dudi", "ade4")
>>>>>       
>>>>>           
>>>> Please do it the right way (package name first!):
>>>>
>>>> importFrom("ade4", "dist.dudi")
>>>>
>>>> Uwe Ligges
>>>>
>>>>
>>>>
>>>>
>>>>    
>>>>
>>>>         
>>>>> importFrom("solve.QP", "quadprog")
>>>>> importFrom("mstree", "ade4")
>>>>> importFrom("neig2mat", "ade4")
>>>>> importFrom("dist.dudi", "ade4")
>>>>> importFrom("dudi.pca", "ade4")
>>>>> importFrom("dudi.coa", "ade4")
>>>>> importFrom("knearneigh", "spdep")
>>>>>
>>>>> i obtain :
>>>>> Namespace dependencies not required:
>>>>>   dist.dudi dudi.coa dudi.pca knearneigh mstree neig2mat solve.QP
>>>>>
>>>>> if i delete the importFrom lines
>>>>> i get an error about "loading / namespace not succesful" for svcr
>>>>>
>>>>> i think the solution is not far but it is disturbing
>>>>>
>>>>> thank for help
>>>>>
>>>>> ---
>>>>> Nicolas
>>>>>
>>>>>
>>>>> Duncan Murdoch a écrit :
>>>>>
>>>>>      
>>>>>
>>>>>           
>>>>>> On 6/12/2006 12:25 PM, Nicolas Turenne wrote:
>>>>>>
>>>>>>        
>>>>>>
>>>>>>             
>>>>>>> in that sense, it is useless to load the library from R source 
>>>>>>> code making my package
>>>>>>> which is supposed to include it and load it
>>>>>>>
>>>>>>> so if i understand the R philosophy it is not possible to load 
>>>>>>> dll from outside ;
>>>>>>> the user has to load my package  and manually has to load the 
>>>>>>> necessary libraries
>>>>>>> each time he has to use my library,  right ?
>>>>>>>           
>>>>>>>               
>>>>>> Not at all.  When set up correctly, the user should just need to say
>>>>>> library(svcR) and all necessary packages and DLLs will be loaded.
>>>>>>
>>>>>> The way to specify other packages is through the "Depends" line in 
>>>>>> the DESCRIPTION file, and/or the import/importFrom lines in your 
>>>>>> NAMESPACE file.
>>>>>>
>>>>>> Duncan Murdoch
>>>>>>
>>>>>>        
>>>>>>
>>>>>>             
>>>>>>> -- 
>>>>>>> Nicolas
>>>>>>>
>>>>>>> Prof Brian Ripley a écrit :
>>>>>>>
>>>>>>>          
>>>>>>>
>>>>>>>               
>>>>>>>> And also to load  the package, maybe with
>>>>>>>>
>>>>>>>> rterm R_DEFAULT_PACKAGES=NULL
>>>>>>>>
>>>>>>>>            
>>>>>>>>
>>>>>>>>                 
>>>>>>>>> library(svcR)
>>>>>>>>>               
>>>>>>>>>                   
>>>>>>>> as these messages often indicate missing package dependencies.
>>>>>>>>
>>>>>>>>            
>>>>>>>>
>>>>>>>>                 
>>>>>>>>>> * checking package subdirectories ... WARNING
>>>>>>>>>> Subdirectory 'src' contains no source files.
>>>>>>>>>> * checking R files for syntax errors ... OK
>>>>>>>>>> * checking R files for library.dynam ... OK
>>>>>>>>>> * checking S3 generic/method consistency ... WARNING
>>>>>>>>>> Erreur : le chargement du package / espace de noms a echoue' 
>>>>>>>>>> pour 'svcR'
>>>>>>>>>> Sequence d'appel :
>>>>>>>>>> 2: stop(gettextf("package/namespace load failed for '%s'",
>>>>>>>>>> libraryPkgName(packag
>>>>>>>>>> e)),
>>>>>>>>>>        call. = FALSE, domain = NA)
>>>>>>>>>> 1: library(package, lib.loc = lib.loc, character.only = TRUE, 
>>>>>>>>>> verbose =
>>>>>>>>>> FALSE)
>>>>>>>>>> Execution arrete'e
>>>>>>>>>> See section 'Generic functions and methods' of the 'Writing R 
>>>>>>>>>> Extensions'
>>>>>>>>>> manual.
>>>>>>>>>> * checking replacement functions ... WARNING
>>>>>>>>>> Erreur : le chargement du package / espace de noms a echoue' 
>>>>>>>>>> pour 'svcR'
>>>>>>>>>> Sequence d'appel :
>>>>>>>>>> 2: stop(gettextf("package/namespace load failed for '%s'",
>>>>>>>>>> libraryPkgName(packag
>>>>>>>>>> e)),
>>>>>>>>>>                 
>>>>>>>>>>                     
>>>>>>>>>               
>>>>>>>>>                   
>>>>>>> ______________________________________________
>>>>>>> R-devel at r-project.org mailing list
>>>>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>>>>           
>>>>>>>               
>>>>>>         
>>>>>>             
>>>>> ______________________________________________
>>>>> R-devel at r-project.org mailing list
>>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>>       
>>>>>           
>>>>     
>>>>         
>>> ______________________________________________
>>> R-devel at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>   
>>>       
>>
>>



More information about the R-devel mailing list