Best Practices for Roxygen Imports/Depends?

被刻印的时光 ゝ 提交于 2019-12-14 03:47:32

问题


I'm writing a small convenience package for accessing a private API, and am using httr functions to conduct the requests. I'm also using Roxygen to handle documentation, etc. I'm importing httr functions as such:

#' Get a page of data from the specified endpoint.
#' @keywords internal
#' @importFrom httr GET
#'
get_data <- function(url, headers, page_number) {
  # Add querystring for page
  url_with_page <- paste0(url, "?page=", page_number)
  message("Downloading: ", url_with_page)
  # Get API response
  response <- GET(url_with_page, headers)
  return(response)
}

However, when you try to run the package with no pre-loaded packages, I get namespace errors:

Error in get_data(url, headers, 1) : 
  could not find function "GET"

I typically defer to Hadley's expertise on this sort of thing, but is this a good case for using the Depends field as well as/rather than Imports?

Edit: my NAMESPACE generated by Roxygen.

# Generated by roxygen2 (4.1.1): do not edit by hand

export(get_export)
export(get_exports)
export(get_metadata)
importFrom(httr,GET)
importFrom(httr,add_headers)
importFrom(httr,content)
importFrom(jsonlite,fromJSON)
importFrom(jsonlite,rbind.pages)

Edit: my DESCRIPTION file.

Package: APIpack
Type: Package
Title: APIpack
Version: 0.1
Date: 2016-01-04
Authors: "Matt Policastro"
Description: This package provides a set of convenience functions.
License: Proprietary
LazyData: TRUE
Imports: httr,
    jsonlite
Suggests: testthat

来源:https://stackoverflow.com/questions/35136366/best-practices-for-roxygen-imports-depends

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