微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

创建具有依赖项的R包

我正在尝试编写我的第一个R包.包中的函数取决于RCurl包中的getURL()函数.我按照教程:
http://r-pkgs.had.co.nz/
http://hilaryparker.com/2014/04/29/writing-an-r-package-from-scratch/

我安装了RTools,devtools和roxygen2来编写文档和构建软件包.

我的包名是“waterml”.在我的包中,我有文件夹R,包含3个文件GetSites.R,Getvariables.R,GetValues.R.每个文件都有一个功能

#' GetSites
#' @import XML
#' @importFrom RCurl getURL
#' This function gets the table of sites from the Waterml web service
#' @param server The URL of the web service ending with .asmx,#'  for example: http://worldwater.byu.edu/interactive/rushvalley/services/cuahsi_1_1.asmx
#' @keywords waterml
#' @export
#' @examples
#' GetSites("http://worldwater.byu.edu/interactive/rushvalley/services/cuahsi_1_1.asmx")

GetSites <- function(server) {
  sites_url <- paste(server,"/GetSitesObject",sep="")
  text <- RCurl::getURL(sites_url)
  doc <- xmlRoot(xmlTreeParse(text,getDTD=FALSE,useInternalNodes = TRUE))
  return(doc)
}

现在,我尝试构建包:

library(devtools)
document()

document()步骤完成且没有错误.现在我跑:

setwd("..")
install("waterml")

但我得到错误

* installing *source* package 'waterml' ...
** R
** preparing package for lazy loading
Error : object 'function' is not exported by 'namespace:RCurl'
ERROR: lazy loading Failed for package 'waterml'
* removing 'C:/Program Files/R/R-3.1.2/library/waterml'

当我检查我的NAMESPACE文件时,它包含一些奇怪的行:

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

export(GetSites)
export(GetValues)
export(Getvariables)
import(RCurl)
import(XML)
importFrom(RCurl,"function")
importFrom(RCurl,This)
importFrom(RCurl,Waterml)
importFrom(RCurl,data)
importFrom(RCurl,from)
importFrom(RCurl,getURL)
importFrom(RCurl,gets)
importFrom(RCurl,of)
importFrom(RCurl,series)
importFrom(RCurl,service)
importFrom(RCurl,sites)
importFrom(RCurl,table)
importFrom(RCurl,the)
importFrom(RCurl,time)
importFrom(RCurl,values)
importFrom(RCurl,variables)
importFrom(RCurl,web)

我认为错误在声明中:

importFrom(RCurl,"function")

任何想法可能是什么问题?我是否在我的函数文档中正确使用了@importFrom?

解决方法

更改:

#' GetSites
#' @import XML
#' @importFrom RCurl getURL
#' This function gets the table of sites from the Waterml web service
#' @param server The URL of the web service ending with .asmx,

至:

#' GetSites
#'
#' This function gets the table of sites from the Waterml web service
#'
#' @import XML
#' @importFrom RCurl getURL
#' @param server The URL of the web service ending with .asmx,

roxygen2正在读取@importFrom之后的行,并假设每个单词都是您要导入的函数.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐