importing packages in package development

I am building a function in a package, but I get this error message:

Error in leaflet::leaflet(options = leafletOptions(minZoom = min_zoom, :
could not find function "%>%"

  • Am I importing correctly
  • Is this the way to use use_this?
  • Should I use `use_this::use_package("leaflet") instead of having it in the roxygen section?

I followed the magrittr section advice here: Should a package import all the magrittr package just to use the pipe in its functions?

#' Creates a leaflet map with the  Mapbox basemap
#' Requires the config.yml file to get the mapbox credentials
#' @params min_zoom The minimum zoom value (default = 12)
#' @params max_zoom The maximum zoom value (default = 19)
#' @import leaflet
#' @import magrittr
#' @return leaflet map
# the map

base_cat_leaflet <- function(min_zoom = 12, max_zoom = 19){
  usethis::use_pipe() #
  leaflet::leaflet(options = leafletOptions(minZoom = min_zoom,
                                   maxZoom = max_zoom)) %>%
    addTiles() %>%
    # maximum bounds - map won't go past these extents - from st_bbox of the com_border_poly
    setMaxBounds(144.89696, -37.85066, 144.99130, -37.77545)

Worked it out. The NAMESPACE document wasn't updating. use_this::use_pipe() is the way to go. Just needed to delete the existing namespace file, then run devtools::document() again.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.