本文介绍了如何正确使用R软件包中其他软件包的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对此我有些困惑.我有一个R包,该包具有小的功能(不是包的市长部分),其中调用了psych包的principal函数.如何在DESCRIPTION和NAMESPACE中正确指定?

I am a bit confused about this. I have an R package that has a small function (not a mayor part of the package) in which the principal function of the psych package is called. How do I correctly specify this in DESCRIPTION and NAMESPACE?

在DESCRIPTION中设置Depends: psych可确保每次加载我的软件包时都加载了psych软件包.这行得通,但是对于我的软件包中的一小部分似乎是多余的.

Setting Depends: psych in DESCRIPTION makes sure the psych package is loaded every time my package is loaded. This works, but it seems redundant for such a small part of my package.

在函数中设置Suggests: psych并输入require("psych")是我现在要做的,但是,如果未安装psych,这将不起作用,并且这样做似乎是错误的方式(编写R扩展说明该建议主要是为了举例).

Setting Suggests: psych and entering a require("psych") in the function is what I do now, however this does not work if psych is not installed, and seems to be the wrong way of doing this (writing R extensions says that suggest is meant mainly for examples).

我认为我需要导入该功能.我尝试在DESCRIPTION中设置Imports: psych,在名称空间中设置importFrom(psych,"principal").可以,但是在没有安装psych的计算机上,加载我的软件包时会出现错误.

I think I need to import the function. I tried setting Imports: psych in DESCRIPTION and importFrom(psych,"principal") in NAMESPACE. This works, but on a computer that does not has psych installed it gives an error when loading my package.

推荐答案

您需要回答的基本问题是:您是否希望该功能对程序包的所有用户都可用而无需付出更多努力?".如果是,则使用import +适当的名称空间声明,如果否,则使用建议并在require("psych")返回FALSE时显示提示性错误消息.

The basic question you need to answer is: "do you want the function to be available to all users of the package without further effort?". If yes, then use imports + the appropriate namespace declarations, if no, then use suggests and print an informative error message if require("psych") returns FALSE.

我不理解您与进口有关的投诉:但是在未安装psych的计算机上,加载我的软件包时出现错误".如果您的包裹在包装箱中,这也是如此!

I don't understand your import related complaint that: "but on a computer that does not has psych installed it gives an error when loading my package". This is also true if your package is in depends!

这篇关于如何正确使用R软件包中其他软件包的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-02 19:12