[英]Why doesn't my package function find other non-export tagged functions?
I've read most of Hadley Wickham's great book: http://r-pkgs.had.co.nz/ , but I'm confused as to why my functions within my package can't find my other non-exported functions. 我已经阅读了大多数Hadley Wickham的好书: http : //r-pkgs.had.co.nz/ ,但我很困惑为什么我的包中的函数找不到我的其他非导出函数。
Eg I have 我有
#' @export
#' @import ggmap
#' @import hexbin
map <- function(return.query, zoom, maptype, histObj) {
UseMethod("map")
}
#'
map.querySold <- function(query, zoom = 11, maptype = "roadmap") {
My Code
}
Running this with a clean enviroment and loading my package generates error: 使用干净的环境运行并加载我的包会产生错误:
> map(x) # x is of class querySold
Error in UseMethod("map") :
no applicable method for 'map' applied to an object of class "c('querySold', 'data.frame')"
What is wrong and how can I fix this? 有什么问题,我该如何解决这个问题? I thought that internal functions where always available to all other functions within the package? 我认为内部函数总是可用于包中的所有其他函数? It is not until I load all functions with devtools::load_all(".")
that it works. 直到我用devtools::load_all(".")
加载所有函数它才有效。
I suspect you haven't @export
map.querySold
. 我怀疑你没有@export
map.querySold
。 Try the following: 请尝试以下方法:
Put @export
right before the first map
function. 将@export
放在第一个map
函数之前。
#' @import ggmap
#' @import hexbin
#' @export
map <- function(return.query, zoom, maptype, histObj) {
UseMethod("map")
}
And add @export
here 并在此处添加@export
#'@export
map.querySold <- function(query, zoom = 11, maptype = "roadmap") {
My Code
}
Then run devtools::document()
and check the NAMESPACE
file. 然后运行devtools::document()
并检查NAMESPACE
文件。
If this doesn't work, it might be helpful to post your NAMESPACE
. 如果这不起作用,发布您的NAMESPACE
可能会有所帮助。 I am thinking you should have 我在想你应该有的
S3method(map.querySold)
export(map)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.