I'm trying to write my first R package. The functions in the package depend on the getURL() function from the RCurl package. I followed the tutorials on: http://r-pkgs.had.co.nz/ and http://hilaryparker.com/2014/04/29/writing-an-r-package-from-scratch/
I installed RTools, devtools and roxygen2 for writing the documentation and building the package.
The name of my package is "waterml". In my package I have the folder R with 3 files GetSites.R , GetVariables.R, GetValues.R. Each file has one function:
#' 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)
}
Now, I try to build the package:
library(devtools)
document()
The document() step completes without error. Now I run:
setwd("..")
install("waterml")
But I get the error:
* 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'
When I checked my NAMESPACE file, it contains some strange lines:
# 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)
I think that the error is in the statement:
importFrom(RCurl, "function")
Any ideas what could be the problem? Am I using the @importFrom in the documentation of my function correctly?
Open a new project in RStudio. Go to the 'File' menu and click on 'New Project. ' Then select 'New Directory,' and 'R Package' to create a new R package.
A dependency is a code that your package needs to run. Dependencies are managed by two files. The DESCRIPTION manages dependencies at the package level; i.e. what packages needs to be installed for your package to work. R has a rich set of ways to describe different types of dependencies.
The R packages dplyr and sf import the operator %>% from the R package magrittr. Of course the package must be loaded before by using e.g.
Change:
#' 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,
To:
#' 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
is reading the line following @importFrom
and assuming each word is a function you want to import.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With