4
votes

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

1 Answers

4
votes

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)