【发布时间】:2015-02-06 11:58:39
【问题描述】:
我正在尝试编写我的第一个 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 吗?
【问题讨论】:
标签: r dependencies package rcurl roxygen2