- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建一个 R 包,它将使用 plyr
中的单个函数 。根据this roxygen2 vignette :
If you are using just a few functions from another package, the recommended option is to note the package name in the Imports: field of the DESCRIPTION file and call the function(s) explicitly using ::, e.g., pkg::fun().
听起来不错。我正在使用plyr::ldply()
- 完整通话 ::
- 所以我列出plyr
在Imports:
在我的DESCRIPTION
文件。但是,当我使用devtools::check()
时我明白了:
* checking dependencies in R code ... NOTE
All declared Imports should be used:
‘plyr’
All declared Imports should be used.
为什么我会收到此注释?
我可以通过添加@importFrom dplyr ldply
来避免这条注释。在使用 plyr
的文件中,但后来我结束了,但有 ldply
在我的包命名空间中。我不想要,也不应该需要,因为我正在使用 plyr::ldply()
我单次使用该功能。
如有任何指点,我们将不胜感激!
(This question可能相关。)
最佳答案
如果ldply()
对于你的包的功能很重要,那么你确实希望它出现在你的包命名空间中。这就是命名空间导入的要点。您需要的函数应该位于包命名空间中,因为这是 R 首先查找函数定义的位置,然后再遍历基本命名空间和附加的包。这意味着无论加载或卸载什么其他包、附加或未附加任何其他包,您的包都将始终可以访问该功能。在这种情况下,请使用:
@importFrom plyr ldply
您可以直接引用 ldply()
而无需使用 plyr::
前缀,就像它是包中的另一个函数一样。
如果 ldply()
不是那么重要 - 也许它只在不常用的函数中调用一次 - 那么,Writing R Extensions 1.5.1给出以下建议:
If a package only needs a few objects from another package it can use a fully qualified variable reference in the code instead of a formal import. A fully qualified reference to the function
f
in packagefoo
is of the formfoo::f
. This is slightly less efficient than a formal import and also loses the advantage of recording all dependencies in theNAMESPACE
file (but they still need to be recorded in theDESCRIPTION
file). Evaluatingfoo::f
will cause packagefoo
to be loaded, but not attached, if it was not loaded already—this can be an advantage in delaying the loading of a rarely used package.
(我认为这个建议实际上有点过时,因为它意味着 DESCRIPTION
和 NAMESPACE
之间的分离比当前存在的更多。)这意味着您应该使用 @import plyr
并将该函数引用为 plyr::ldply()
。但实际上,它实际上建议将 plyr
放入 DESCRIPTION
的 Suggests
字段中,这并不完全由 roxygen2 标记容纳,也不完全符合符合R CMD 检查
。
总之,官方的说法是,Hadley 的建议(您引用的)仅适用于很少使用的包(和/或需要花费大量时间来完成的包)中很少使用的函数。加载)。否则,只需像 WRE 建议的那样执行 @importFrom
即可:
Using
importFrom
selectively rather thanimport
is good practice and recommended notably when importing from packages with more than a dozen exports.
关于R 与 roxygen2 : How to use a single function from another package?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36574141/
在下面的方法中,如何将第一个Single的结果传递给第二个Single? 如现在所写,当它返回时,somethingId 是空的。如果我将返回的 Single.just(somethingId) 中的
我发现很多帖子都在回答类似的问题(例如“如何用 / 替换 \”或“如何替换 \\” by \”。我理解所有这些,但没有一个能解决我的特殊问题。这里是: 我正在从注册表中读取路径字符串,其中包含“///
注意:事实证明,toCompletable() 并非错误,而是调用代码。调用代码使得更改此方法使其工作(或不工作)。 我有以下方法。它返回一个 Single。有用。执行内部代码,以便 remoteDa
react-native repo here 中的一个文件中有一段代码如下图: export type Operation = & {instanceID: DebugID} & (
当使用带有 Single() 的 LINQ 时,我的代码行总是带有绿色下划线,并带有建议“替换为对 single 的单一调用”。这是什么意思?下面是产生该建议的一行代码示例: var user = d
讨论来自 this answer让我好奇。哪个更快: someEnumerable.Single(predicate); 或 someEnumerable.Where(predicate).Singl
我正在使用 Keycloak 作为单点登录 (SSO) 平台的 OP。我已经将我的两个 Web 应用程序连接到 Keycloak,以便使用单点登录功能。 此外,我已经制作了一个应用程序,当注销时将被重
我的步骤是: 创建单个值 x - 可能会占用一些 CPU 资源 使用值x来执行IO操作。这已经返回 Completable 返回x 所以我想这样做: Single result =
我想知道是否有人可以阐明这个问题,什么时候使用 Single.fromCallable( ()-> myObject ) 代替 Single.just(myObject) 根据文档,Single.fr
我有两个 Singles 来源,我将它们组合成一个 Single of Pair。 假设我们对这些来源有两种方法: private Single single1() {} private Single
我想将单个 Intel CPU 内核的速度与单个 nVidia GPU 内核的速度(即:单个 CUDA 代码、单个线程)进行比较。我确实实现了以下简单的二维图像卷积算法: void convoluti
我在实现 Ping Federate 时遇到此问题 Error - Single Sign-On Single sign-on authentication was unsuccessful (ref
我有几个 api 调用(Rx singles),我想将它们组合成一个 Single。我正在使用 Single.merge 尝试合并这些调用的结果,但是当我订阅响应时,我得到一个空数组,因为订阅已经发生
早上好。我的代码有问题 bootsfaces 。我需要我的 DataTable 支持单行选择,但不支持多行选择。但是,我的表格始终只使用多项选择。 这是我的代码: 我没有进行简单的选择,因为我引用了
我怎样才能像下面的代码那样使用字符串。 $str = 'Is yo"ur name O'reil"ly?'; 上面的代码只是一个例子..我需要使用包含单引号和双引号的大 html 模板。我尝试了 Ad
我有一组地理空间+时间数据和一些附加属性,我将在 map 上显示这些数据。该集合目前有几百万份文件,并且会随着时间的推移而增加。 每个文档都有以下字段: 位置:[geojson 对象] 日期:[日期对
我目前在 .NET 2.0 下使用 SharpZipLib,通过它我需要将单个文件压缩为单个压缩存档。为此,我目前正在使用以下内容: string tempFilePath = @"C:\Users\
我有 table create table1( column1 number(10, column2 number(10), column3 number(10) ); column1是主
考虑下面这段代码,我正在尝试使用 Executors.newFixedThreadPool(1).asCoroutineDispatcher()创建单线程调度程序;我想要 launch(singleT
我面临着困惑,举个例子 4 Single: val s1 : Single = service1.execute().subscribeOn(io()) val s2 : Single = servi
我是一名优秀的程序员,十分优秀!