"pkg :: name"的主要用途是: [英] The main use(s) of "pkg::name"

查看:295
本文介绍了"pkg :: name"的主要用途是:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到SO上的一些答案包含pkg::name的使用,其中name通常是一个函数.

I noticed that some answers on SO contain the use of pkg::name where name is typically a function.

library(pkg); ... name()require(pkg); ... name()相比,这有什么优点? R帮助,(help("::"))说

What is the advantage of this over library(pkg); ... name() or require(pkg); ... name()? R help, (help("::")) says

对于包pkg,pkg :: name返回名称空间pkg中导出的变量名称的值,...如果在调用之前未加载名称空间,则将加载该名称空间,但该软件包将不会附加到该名称空间.搜索路径.

For a package pkg, pkg::name returns the value of the exported variable name in namespace pkg, ... The namespace will be loaded if it was not loaded before the call, but the package will not be attached to the search path.

这是否意味着在使用python的过程中使用该函数而不会增加加载整个程序包的额外内存(即,等同于import <function> from <package>)?还是只是在存在歧义时告诉R使用此包中的函数的一种方法?

Does this mean that the function is used without the additional memory loss of loading the entire package, (ie, is it equivalent to import <function> from <package>) in python? Or is it simply a means of telling R use the function from this package when there may be ambiguities?

我的问题与Rscript中或直接在控制台中对::的使用有关,因此不是链接问题的重复,因为该问题中的OP正在讨论使用stats4包中的函数的过程包装开发项目.另一方面,此帖子中似乎有答案,这为我的问题提供了一些启示.感谢您的链接. (请注意以下有关Meta的讨论:

My question relates the use of :: in an Rscript or directly in the console and so is not a duplicate of the linked question as the OP in that question is discussing the use of of functions from the stats4 package during a package development project. On the other hand, there appear to be answers within this post that shed some light on my question, however. Thanks for the link. (Note the following discussion on Meta: duplicates flag)

推荐答案

它避免了名称空间冲突,但仍必须加载pkg.

It avoids namespace collisions but it still has to load the pkg.

示例=>我这样做了:

pryr::mem_used()
dplyr::filter(mtcars, cyl==4)
pryr::mem_used()

在一个R实例中:

pryr::mem_used()
library(dplyr)
filter(mtcars, cyl==4)
pryr::mem_used()

在另一个.

内存为:27.7 MB/30.6 MB 第二个之前/之后的内存为:27.7 MB/30.7 MB

mem before/after for the 1st was: 27.7 MB / 30.6 MB mem before/after for the 2nd was: 27.7 MB / 30.7 MB

我没有进行多次测试,也没有看到差异是否在四舍五入,或者没有其他东西,但是IMO没有真正的节省之处.

I didn't do multiple tests or see if the difference was rounding or something else, but no there were no real savings there IMO.

这篇关于"pkg :: name"的主要用途是:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆