[英]When writing my own R package, I can't seem to get other packages to import correctly
Alright, first attempt at writing an R package and I'm stuck. 好吧,第一次尝试写一个R包,我被卡住了。 Here's how I create the package:
这是我创建包的方式:
package.skeleton("pkg",code_files=some.filenames)
roxygenize("okg")
I'm using roxygen2 and have the following imports in my "pkg-package.R" file: 我正在使用roxygen2并在我的“pkg-package.R”文件中输入以下内容:
@import data.table zoo lubridate
From a terminal, I then run: 从终端,我然后运行:
R CMD build pkg
R CMD check pkg
R CMD install pkg
During the check phase, I get the following warnings: 在检查阶段,我收到以下警告:
** preparing package for lazy loading
**准备延迟装载包
Warning: replacing previous import 'hour' when loading 'lubridate'警告:加载'lubridate'时替换上一个导入'小时'
Warning: replacing previous import 'mday' when loading 'lubridate'警告:在加载'lubridate'时替换先前的导入'mday'
Warning: replacing previous import 'month' when loading 'lubridate'警告:加载'lubridate'时替换上一个导入'月'
Warning: replacing previous import 'wday' when loading 'lubridate'警告:在加载'lubridate'时替换先前的导入'wday'
Warning: replacing previous import 'week' when loading 'lubridate'警告:加载'lubridate'时替换上一个导入'周'
Warning: replacing previous import 'yday' when loading 'lubridate'警告:在加载'lubridate'时替换先前的导入'yday'
Warning: replacing previous import 'year' when loading 'lubridate'警告:加载'lubridate'时替换上一个导入'年'
** help** 救命
* installing help indices*安装帮助索引
** building package indices ...**建筑包装指数......
** testing if installed package can be loaded**测试是否可以加载已安装的软件包
Warning messages:警告信息:
1: replacing previous import 'hour' when loading 'lubridate'1:加载'lubridate'时替换先前的导入'小时'
2: replacing previous import 'mday' when loading 'lubridate'2:加载'lubridate'时替换先前的导入'mday'
3: replacing previous import 'month' when loading 'lubridate'3:加载'lubridate'时替换上一个导入'月'
4: replacing previous import 'wday' when loading 'lubridate'4:加载'lubridate'时替换先前的导入'wday'
5: replacing previous import 'week' when loading 'lubridate'5:加载'lubridate'时替换上一个导入'周'
6: replacing previous import 'yday' when loading 'lubridate'6:加载'lubridate'时替换先前的导入'yday'
7: replacing previous import 'year' when loading 'lubridate'7:加载'lubridate'时替换上一个导入'年'
I'm really not sure what to make of those, but they seem like typical warnings from overwriting stuff in namespace. 我真的不确定如何制作这些,但它们似乎是覆盖命名空间中的东西的典型警告。 In any case, I am able to install the package, but here's what happens when I try to use it:
在任何情况下,我都可以安装软件包,但是当我尝试使用它时会发生什么:
library(pkg)
库(PKG)
Overriding + and - methods for POSIXt, Date and difftime覆盖POSIXt,Date和difftime的+和 - 方法
Warning messages:警告信息:
1: replacing previous import 'hour' when loading 'lubridate'1:加载'lubridate'时替换先前的导入'小时'
2: replacing previous import 'mday' when loading 'lubridate'2:加载'lubridate'时替换先前的导入'mday'
3: replacing previous import 'month' when loading 'lubridate'3:加载'lubridate'时替换上一个导入'月'
4: replacing previous import 'wday' when loading 'lubridate'4:加载'lubridate'时替换先前的导入'wday'
5: replacing previous import 'week' when loading 'lubridate'5:加载'lubridate'时替换上一个导入'周'
6: replacing previous import 'yday' when loading 'lubridate'6:加载'lubridate'时替换先前的导入'yday'
7: replacing previous import 'year' when loading 'lubridate'7:加载'lubridate'时替换上一个导入'年'
d <- my.function(arg1, arg2)d < - my.function(arg1,arg2)
Error in MATCH(x, x) : could not find function "MATCH"MATCH(x,x)出错:找不到函数“MATCH”
Using traceback(), I found out that this is being generating during a call to merge.zoo(). 使用traceback(),我发现这是在调用merge.zoo()期间生成的。 So I tried loading zoo by hand during my R session and voila, then the function works correctly without the error message.
所以我尝试在我的R会话期间手动加载动物园,然后功能正常,没有错误消息。
I have tried changing the ordering of the imports by hand in both the "pkg-package.R" file, as well as in NAMESPACE. 我已经尝试在“pkg-package.R”文件和NAMESPACE中手动更改导入的顺序。 Based on something I found elsewhere, I have not added any Imports or Depends to DESCRIPTION, however.
根据我在其他地方找到的东西,我没有添加任何Imports或Depends来描述。 Help?
救命?
The warnings are because data.table and lubridate both define a symbol hour
, etc; 警告是因为data.table和lubridate都定义了一个符号
hour
等; see data.table::hour
and lubridate::hour
. 请参阅
data.table::hour
和lubridate::hour
。 You could avoid this by importing just the functions from lubridate / data.table that you want, rather than the whole package; 你可以通过只导入你想要的lubridate / data.table中的函数来避免这种情况,而不是整个包; a standard NAMESPACE file would contain
标准的NAMESPACE文件将包含
importFrom(lubridate, hour)
for instance. 例如。 In roxygen2 you would use the tag:
在roxygen2中你会使用标签:
@importFrom lubridate hour
The MATCH problem is probably because merge
is dispatching incorrectly, probably because zoo should have in its name space S3method(merge, zoo)
rather than export(merge.zoo)
, as described in Writing R Extensions, 1.6.2. MATCH问题可能是因为
merge
调度错误,可能是因为zoo应该在其名称空间S3method(merge, zoo)
而不是export(merge.zoo)
,如Writing R Extensions,1.6.2中所述。 The solution here is to contact the maintainer of zoo
, packageDescription('zoo')$Maintainer
(the maintainer is sufficiently versed in R that I feel like I've mis-diagnosed...). 这里的解决方案是联系
zoo
的维护者, packageDescription('zoo')$Maintainer
(维护人员对R非常熟悉,我觉得我错误地诊断了......)。
作为MATCH错误的临时解决方法,我已经成功列出了包的DESCRIPTION
文件的Depends:
部分下的zoo
包。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.