Skip to content

Commit

Permalink
check if suggested packages are available
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel-rosa committed Jul 28, 2015
1 parent 385e7d9 commit dbb8380
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 10 deletions.
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ export(whichInteger)
export(whichNumeric)
export(whichNumint)
import(Rcpp)
import(lattice)
import(latticeExtra)
importFrom(graphics,plot)
importFrom(stats,update)
useDynLib(pedometrics)
9 changes: 9 additions & 0 deletions R/bbox2sp.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
9 changes: 9 additions & 0 deletions R/buildMS.R
Original file line number Diff line number Diff line change
Expand Up @@ -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("<formula> is a mandatory argument")
Expand Down
8 changes: 7 additions & 1 deletion R/cdfPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"}.
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion R/cdfTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
6 changes: 6 additions & 0 deletions R/cont2cat.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions R/coordenadas.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions R/gcpDiff.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
#'
Expand Down
2 changes: 1 addition & 1 deletion R/pedometrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
#' }
#'
Expand Down
11 changes: 10 additions & 1 deletion R/plotESDA.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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("<z> is a mandatory argument")
}
Expand Down
12 changes: 12 additions & 0 deletions R/plotHD.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions R/plotMS.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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("<obj> is a mandatory argument")
}
Expand Down
12 changes: 10 additions & 2 deletions R/statsMS.R
Original file line number Diff line number Diff line change
Expand Up @@ -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("<model> is a mandatory argument")
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 8 additions & 2 deletions R/stepVIF.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'")
}
Expand Down
5 changes: 5 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit dbb8380

Please sign in to comment.