diff --git a/NAMESPACE b/NAMESPACE index 28a81dd..0a0d245 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -37,4 +37,8 @@ export(whichInteger) export(whichNumeric) export(whichNumint) import(Rcpp) +import(lattice) +import(latticeExtra) +importFrom(graphics,plot) +importFrom(stats,update) useDynLib(pedometrics) diff --git a/R/bbox2sp.R b/R/bbox2sp.R index 92e235b..b9dae26 100644 --- a/R/bbox2sp.R +++ b/R/bbox2sp.R @@ -37,6 +37,15 @@ bbox2sp <- function (obj, sp = "SpatialPolygons", keep.crs = TRUE) { + # Check if suggested packages are installed + pkg <- c("sp") + id <- !sapply(pkg, requireNamespace, quietly = TRUE) + if (any(id)) { + pkg <- paste(pkg[which(id)], collapse = " ") + stop(paste("Package(s) needed for this function to work but not", + "installed: ", pkg, sep = ""), call. = FALSE) + } + if (!inherits(obj, "Spatial")) { stop ("obj should be of class Spatial") } diff --git a/R/buildMS.R b/R/buildMS.R index 5702b32..971d21e 100644 --- a/R/buildMS.R +++ b/R/buildMS.R @@ -104,6 +104,15 @@ buildMS <- aic = FALSE, aic.direction = "both", aic.trace = FALSE, aic.steps = 5000, ...) { + # Check if suggested packages are installed + pkg <- c("MASS", "pbapply") + id <- !sapply(pkg, requireNamespace, quietly = TRUE) + if (any(id)) { + pkg <- paste(pkg[which(id)], collapse = " ") + stop(paste("Package(s) needed for this function to work but not", + "installed: ", pkg, sep = ""), call. = FALSE) + } + # check arguments ########################################################## if (missing(formula)) { stop(" is a mandatory argument") diff --git a/R/cdfPlot.R b/R/cdfPlot.R index 68245ef..2ef5e96 100644 --- a/R/cdfPlot.R +++ b/R/cdfPlot.R @@ -56,7 +56,7 @@ #' parameters are the mean, the median, and a percentile defined by the #' argument \code{conflev}. The legend displays de actual values of all three #' parameters, including the standard deviation of the mean. The percentile -#' value is calculated using \code{spsurvey::spsurvey::interp.cdf()}. +#' value is calculated using \code{spsurvey::interp.cdf()}. #' @param round Numeric to set the rounding level of the parameters of the CDF. #' @param col.param Color of the lines showing the parameters of the CDF. #' Defaults to \code{col.param = "black"}. @@ -113,6 +113,12 @@ cdfPlot <- conflev = 95, show.param = TRUE, round = 0, col.param = "black", ...) { + # Check if suggested packages are installed + if (!requireNamespace("spsurvey", quietly = TRUE)) { + stop(paste("Package 'spsurvey' needed for this function to work. ", + "Please install it.", sep = ""), call. = FALSE) + } + op <- graphics::par(mgp = c(1.7, 0.6, 0), mar = c(3, 3, 2, 4) + 0.1) obj <- obj ind <- ind diff --git a/R/cdfTable.R b/R/cdfTable.R index 2c95b70..b581693 100644 --- a/R/cdfTable.R +++ b/R/cdfTable.R @@ -69,7 +69,13 @@ # FUNCTION ##################################################################### cdfTable <- function(x, type = "xy", rounding = 0, tex = FALSE, data.frame = FALSE) { - + + # Check if suggested packages are installed + if (!requireNamespace("xtable", quietly = TRUE)) { + stop(paste("Package 'xtable' needed for this function to work. ", + "Please install it.", sep = ""), call. = FALSE) + } + if(type == "xy") { tb <- data.frame(c("Mean", "Absolute mean", "Squared mean"), round(c(cdfStats(x, "dx")[1, 3], diff --git a/R/cont2cat.R b/R/cont2cat.R index 82b7e12..364ce52 100644 --- a/R/cont2cat.R +++ b/R/cont2cat.R @@ -68,6 +68,12 @@ cont2cat <- function (x, breaks, integer = FALSE) { + # Check if suggested packages are installed + if (!requireNamespace("SpatialTools", quietly = TRUE)) { + stop(paste("Package 'SpatialTools' needed for this function to work. ", + "Please install it.", sep = ""), call. = FALSE) + } + # Process input x_cl <- class(x) x <- as.data.frame(x) diff --git a/R/coordenadas.R b/R/coordenadas.R index b0fd8c4..3a52ee1 100644 --- a/R/coordenadas.R +++ b/R/coordenadas.R @@ -36,6 +36,16 @@ # FUNCTION ##################################################################### coordenadas <- function(x) { + + # Check if suggested packages are installed + pkg <- c("sp") + id <- !sapply(pkg, requireNamespace, quietly = TRUE) + if (any(id)) { + pkg <- paste(pkg[which(id)], collapse = " ") + stop(paste("Package(s) needed for this function to work but not", + "installed: ", pkg, sep = ""), call. = FALSE) + } + coo <- data.frame(x$siteID, sp::coordinates(x)) coo <- coo[order(as.numeric(x$siteID)), ] colnames(coo) <- c("siteID", "xcoord", "ycoord") diff --git a/R/gcpDiff.R b/R/gcpDiff.R index a439e5e..78650e2 100644 --- a/R/gcpDiff.R +++ b/R/gcpDiff.R @@ -55,12 +55,12 @@ #' error statistics will have no meaning at all. #' } #' -#' @param measured Object of class \code{\linkS4class{SpatialPointsDataFrame}} +#' @param measured Object of class \code{SpatialPointsDataFrame} #' with the reference GCP. A column named \sQuote{siteID} giving case names is #' mandatory. See \sQuote{Details}, item \sQuote{Type of data}. #' #' @param predicted An object of class -#' \code{\linkS4class{SpatialPointsDataFrame}} with the point data being +#' \code{SpatialPointsDataFrame} with the point data being #' validated. A column named \sQuote{siteID} giving case names is mandatory. #' See \sQuote{Details}, item \sQuote{Type of data}. #' diff --git a/R/pedometrics.R b/R/pedometrics.R index 5d889a4..c38108b 100644 --- a/R/pedometrics.R +++ b/R/pedometrics.R @@ -22,7 +22,7 @@ #' Package: \tab pedometrics\cr #' Type: \tab Package \cr #' Version: \tab 0.6-3 \cr -#' Date: \tab 2015-07-27 \cr +#' Date: \tab 2015-07-28 \cr #' License: \tab GPL (>= 2) \cr #' } #' diff --git a/R/plotESDA.R b/R/plotESDA.R index 8eb39b0..066cb65 100644 --- a/R/plotESDA.R +++ b/R/plotESDA.R @@ -43,6 +43,7 @@ #' #' @seealso \code{\link[gstat]{variogram}}, \code{\link[pedometrics]{plotHD}}, #' \code{\link[sp]{bubble}}, \code{\link[sp]{spplot}}. +#' @importFrom graphics plot #' @export #' @examples #' # require(gstat) @@ -52,10 +53,18 @@ #' @keywords dplot #' # FUNCTION ##################################################################### -# plotESDA <- function (z, lat, lon, lags, cutoff, width = c(cutoff / 20)) { + # Check if suggested packages are installed + pkg <- c("gstat", "sp") + id <- !sapply(pkg, requireNamespace, quietly = TRUE) + if (any(id)) { + pkg <- paste(pkg[which(id)], collapse = " ") + stop(paste("Package(s) needed for this function to work but not", + "installed: ", pkg, sep = ""), call. = FALSE) + } + if (missing(z)) { stop(" is a mandatory argument") } diff --git a/R/plotHD.R b/R/plotHD.R index cbf6676..f69e04b 100644 --- a/R/plotHD.R +++ b/R/plotHD.R @@ -72,6 +72,8 @@ #' @seealso \code{\link[lattice]{histogram}}, #' \code{\link[lattice]{densityplot}}, \code{\link[lattice]{panel.mathdensity}}, #' \code{\link[car]{powerTransform}}, \code{\link[car]{bcPower}}. +#' @import lattice latticeExtra +#' @importFrom stats update #' @export #' @examples #' x <- rnorm(100, 10, 2) @@ -86,6 +88,16 @@ plotHD <- BoxCox = FALSE, col = c("lightgray", "black"), lwd = c(1, 1), lty = "dashed", xlim, ylim, ...) { + # Check if suggested packages are installed + if (!requireNamespace("moments", quietly = TRUE)) { + stop(paste("Package 'moments' needed for this function to work. ", + "Please install it.", sep = ""), call. = FALSE) + } + if (!requireNamespace("car", quietly = TRUE)) { + stop(paste("Package 'car' needed for this function to work. ", + "Please install it.", sep = ""), call. = FALSE) + } + if (BoxCox) { # Check if the variable has negative values diff --git a/R/plotMS.R b/R/plotMS.R index a3fe16e..f95ce33 100644 --- a/R/plotMS.R +++ b/R/plotMS.R @@ -195,6 +195,7 @@ #' #' @seealso \code{\link[lattice]{levelplot}}, \code{\link[lattice]{xyplot}}, #' \code{\link[mvtsplot]{mvtsplot}}. +#' @importFrom stats update #' @export #' @examples #' # This example follows the discussion in section "Details" @@ -218,6 +219,15 @@ plotMS <- size = 0.5, arrange = "desc", color = NULL, xlim = NULL, ylab = NULL, xlab = NULL, at = NULL, ...) { + # Check if suggested packages are installed + pkg <- c("grDevices", "grid", "plyr") + id <- !sapply(pkg, requireNamespace, quietly = TRUE) + if (any(id)) { + pkg <- paste(pkg[which(id)], collapse = " ") + stop(paste("Package(s) needed for this function to work but not", + "installed: ", pkg, sep = ""), call. = FALSE) + } + if (missing(obj)) { stop(" is a mandatory argument") } diff --git a/R/statsMS.R b/R/statsMS.R index 2c9ec1c..1828d15 100644 --- a/R/statsMS.R +++ b/R/statsMS.R @@ -104,7 +104,15 @@ # statsMS <- function (model, design.info, arrange.by, digits) { - + + # Check if suggested packages are installed + pkg <- c("plyr") + id <- !sapply(pkg, requireNamespace, quietly = TRUE) + if (any(id)) { + pkg <- paste(pkg[which(id)], collapse = " ") + stop(paste("Package(s) needed for this function to work but not", + "installed: ", pkg, sep = ""), call. = FALSE) + } if (missing(model)) { stop(" is a mandatory argument") @@ -139,7 +147,7 @@ statsMS <- } r2 <- as.numeric(unlist(sapply(model, summary)["r.squared", ])) adj_r2 <- as.numeric(unlist(sapply(model, summary)["adj.r.squared", ])) - ADJ_r2 <- pedometrics::adjR2(r2, n, p = c(p - 1)) + ADJ_r2 <- adjR2(r2, n, p = c(p - 1)) id <- seq(1, length(n), 1) if (!missing(digits)) { if (length(digits) == 6) { diff --git a/R/stepVIF.R b/R/stepVIF.R index 4f3e78d..1342c5f 100644 --- a/R/stepVIF.R +++ b/R/stepVIF.R @@ -8,8 +8,8 @@ #' predictor variables. #' @param threshold Positive number defining the maximum allowed VIF. Defaults #' to \code{threshold = 10}. -#' @param verbose Logical for indicating if iteration results should be printed. -#' Defaults to \code{verbose = FALSE}. +#' @param verbose Logical for indicating if iteration results should be +#' printed. Defaults to \code{verbose = FALSE}. #' #' @details #' \code{stepVIF} starts computing the VIF of all predictor variables in the @@ -83,6 +83,12 @@ stepVIF <- function (model, threshold = 10, verbose = FALSE) { + # Check if suggested packages are installed + if (!requireNamespace("car", quietly = TRUE)) { + stop(paste("Package 'car' needed for this function to work. ", + "Please install it.", sep = ""), call. = FALSE) + } + if (!inherits(model, "lm")) { stop ("'model' must be of class 'lm'") } diff --git a/cran-comments.md b/cran-comments.md index d66017b..5552679 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,3 +1,8 @@ +## Changes +* Improved existing functions +* Created new functions +* Fix a test failure on R-devel + ## Test environments * ubuntu 12.04 (on travis-ci), R 3.2.1 * x86_64-pc-linux-gnu (ubuntu 14.04), R version 3.2.1 (2015-06-18)