进口/取决于进口的最佳实践?

时间:2016-02-01 17:12:54

标签: r roxygen

我正在编写一个小型便捷软件包来访问私有API,并使用httr函数来执行请求。我还使用Roxygen处理文档等。我导入httr函数:

#' 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)
}

但是,当您尝试运行没有预加载包的包时,我会收到命名空间错误:

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

我通常会在这类事情上遵守Hadley's expertise,但这是使用Depends字段以及/而不是Imports的好例子吗?

编辑:我的NAMESPACE由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)

编辑:我的描述文件。

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

0 个答案:

没有答案