簡體   English   中英

創建具有依賴項的R包

[英]Create an R package with dependencies

我正在嘗試編寫我的第一個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並假設每個字是要導入的功能。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM