Why doesn't my package function find other non-export tagged functions?

耗尽温柔 提交于 2019-12-10 17:35:40

问题


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.

E.g 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.


回答1:


I suspect you haven't @export map.querySold. Try the following:

Put @export right before the first map function.

#' @import ggmap
#' @import hexbin
#' @export
map  <- function(return.query, zoom, maptype, histObj) {

  UseMethod("map")

}

And add @export here

#'@export 
map.querySold  <- function(query, zoom = 11, maptype = "roadmap") {
  My Code
}

Then run devtools::document() and check the NAMESPACE file.

If this doesn't work, it might be helpful to post your NAMESPACE. I am thinking you should have

S3method(map.querySold)
export(map)


来源:https://stackoverflow.com/questions/32277063/why-doesnt-my-package-function-find-other-non-export-tagged-functions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!