What is the benefit of import in a namespace in R? -
R's namespace mechanism assigns a An advantage seems to be that any one can use the function from other packages without enclosing the package and thereby saving the memory is an example in this section. However, the import function should have other benefits. Specifically, the There are functions which are neither S4 Class nor Generic (where it will also be understood to use the import, as mentioned in the example), but / code>, If the function Things can be quite complex with S4 (and S3). A non-generic function such as The package (user name and password via the svn export function which is then visible to the user. In addition, it allows the import functions from other packages, while the profit of exports is clear, I have more problems in understanding the benefits of import. namespace of stats4 package shows:
importFrom ("graphics", plot) importFrom ("stats", optim, qchisq) # # For these, we define methods or (AIC, BIC, Novus) a general generic: importFrom ("statistics", AIC, BIC, COF, clerk, loglink, nodes, profiles, updates, vcov) Export Classes ( Mail, profile., Summary.mL) # # All methods for imported generic: export methods (COEF, CONFY ## Indirect generics who have no way to export here (AIC, BIC, Knox) are imported here optim or qchisq code? foo is imported from the package bar, then found it What does the user do for his search path, for example, by appending a package falcon, in which the function is foo without a namespace, package code suddenly Baz :: Using foo . There are also issues of efficiency (instead of searching through all the symbols on the search path, are found instantly), but it is likely to be trivial for most applications. In the same way, due to the least collision (or the use of unexpected works) and more efficient lookup, importFrom is a code import . graphics :: plot can be promoted in two different packages with a normal (with setGeneric ), and each generic has its own There may be a set of methods. A package author wants to be precise, about which plot is normal, and so see the methods of dispatch tables, their classes and methods. pkg :: Foo always resolves the desired function, it is necessary that PKG was listed in the despectors: field of DESCRIPTION file (maybe in import : But then it seems like a misleading advertisement to not import from PKG), pollutes the user's search path, it includes two symbol lookup and function calls ( :: ); And these are less efficient. The carefully-extended part of the laziness and lack of sight also sees the use of tedious and error prone as :: . readonly ) can generate a NAMESPACE file from an existing package (or at least this is a recent change in the R- Before NAMESPACE started without any package; I have not tried codetoolsBioC on such a package).
Comments
Post a Comment