我有一个已发布的包x
,其中包含cgwtools
运算符的重载。这是源文件!
中的代码:
splatnd.r
这是基于名为`!` <- function (e1, e2)
{
call <- match.call()
original <- function() {
call[[1]] <- quote(base::`!`)
return(eval(call, parent.frame(2)))
}
switch(paste(as.character(call[[2]]), sep = "", collapse = ""),
newdev = dev.new(width = 4.5, height = 4.5, restoreConsole = T),
qapla = cat("batlh tIn chav\n"), return(original()))
}
的{{1}}包中的简洁工具。如果我只是sos
???
代码,它会按预期运行。在过去,至少在source
之前,加载包!
让我按预期运行R 3.2.x
。我最近在Windows 7机器上设置了版本3.2.4和3.3.1,并且明显无法加载。这是一些控制台文本,显示加载cgwtools
!
作为比较,对cgwtools
包执行相同操作会返回我期望的内容:
> getAnywhere(`!`)
A single object matching ‘!’ was found
It was found in the following places
package:base
namespace:base
with value
function (x) .Primitive("!")
> library(cgwtools)
> getAnywhere(`!`)
2 differing objects matching ‘!’ were found
in the following places
package:base
namespace:cgwtools
namespace:base
如果我访问输出,则会显示正确的源代码:
sos
但是,正如缺少文本> getAnywhere(`?`)
2 differing objects matching ‘?’ were found
in the following places
package:sos
package:utils
namespace:utils
namespace:sos
所示,当我尝试运行时,从gui控制台说> getAnywhere(`!`)[2]
function (e1, e2)
{
call <- match.call()
original <- function() {
call[[1]] <- quote(base::`!`)
return(eval(call, parent.frame(2)))
}
switch(paste(as.character(call[[2]]), sep = "", collapse = ""),
newdev = dev.new(width = 4.5, height = 4.5, restoreConsole = T),
qapla = cat("batlh tIn chav\n"), return(original()))
}
<environment: namespace:cgwtools>
时,我收到错误消息package:cgwtools
未找到,即调用!qapla
运算符qapla
。
所以问题是:为什么加载包后.Primitive
包中的!
函数无法被识别?在构建软件包源代码时,我是否做了一些愚蠢的事情,或者我在CRAN构建器中发现了一些错误?
子问题:我无法找出导向命令的任何变体!
&#39;!&#39; cgwtools
不会导致解析错误
回应alexis_laz的查询:
cgwtools::
而且,
qapla
再次建议&#34;!&#34;没有从> search()
[1] ".GlobalEnv" "package:cgwtools" "package:stats"
[4] "package:graphics" "package:datasets" "package:grDevices"
[7] "package:lattice" "package:sos" "package:brew"
[10] "package:utils" "package:methods" "Autoloads"
[13] "package:base"
> cgwtools:::'!'qapla
Error: unexpected symbol in "cgwtools:::'!'qapla"
导出。
另请注意 - 请参阅上面的
> get('!')(qapla)
Error: object 'qapla' not found
> get('!',2)(qapla)
Error: object 'qapla' not found
我可以拉代码:
cgwtools
答案 0 :(得分:3)
感谢@alexis_laz的建议,我回过头来查看NAMESPACE
生成的默认package.skeleton
文件。该文件包含行
exportPattern("^[[:alpha:]]+")
显然,我需要在此文件中添加显式export('!')
行。 (加上每个最近CRAN要求明确import
base
个NAMESPACE
个套餐的新要求,但这是一个单独的问题)
对于没有经验的人(比如我),请注意,在更改index.php
文件后,必须重建包。编辑所述文件是不够的。