创建具有依赖项的R包
发布时间:2020-12-14 04:56:59 所属栏目:百科 来源:网络整理
导读:我正在尝试编写我的第一个R包.包中的函数取决于RCurl包中的getURL()函数.我按照教程: http://r-pkgs.had.co.nz/和 http://hilaryparker.com/2014/04/29/writing-an-r-package-from-scratch/ 我安装了RTools,devtools和roxygen2来编写文档和构建软件包. 我的
我正在尝试编写我的第一个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之后的行,并假设每个单词都是您要导入的函数. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |