yazeng
2015-Sep-12 19:27 UTC
[R] R CRAN check works great on local Mac OS, but failed on Windows (win-builder web). Why?
I have my R package checked on local Mac OS via R CMD check --as-cran. Everything works great: no errors, no warnings, just 1 note about first submission, all test files passed! However, when I submit my .tar.gz package file to the http://win-builder.r-project.org to check on Windows. Some errors occurred when running the examples. The main issue is related to the object created by Matrix. All errors indicated *invalid class "dgCMatrix" object: Dimnames[1] is not a character vector. * Detailed check log is attached below. I checked the examples on local machine line-by-line, but cannot identify the problem. Is the error caused by that maybe the Matrix package was written differently for Mac OS and Windows platforms? /* checking examples ... ** running examples for arch 'i386' ... ERROR Running examples in 'grpregOverlap-Ex.R' failed The error most likely occurred in:> base::assign(".ptime", proc.time(), pos = "CheckExEnv") > ### Name: cv.grpregOverlap > ### Title: Cross-validation for choosing regularization parameter lambda > ### Aliases: cv.grpregOverlap > > ### ** Examples > > ## linear regression, a simulation demo. > set.seed(123) > group <- list(gr1 = c(1, 2, 3),+ gr2 = c(1, 4), + gr3 = c(2, 4, 5), + gr4 = c(3, 5), + gr5 = c(6))> beta.latent.T <- c(5, 5, 5, 0, 0, 0, 0, 0, 5, 5, 0) # true latent > coefficients. > # beta.T <- c(5, 5, 10, 0, 5, 0), true variables: 1, 2, 3, 5; true groups: > 1, 4. > X <- matrix(rnorm(n = 6*100), ncol = 6) > X.latent <- expandX(X, group)Error in validObject(.Object) : invalid class "dgCMatrix" object: Dimnames[1] is not a character vector Calls: expandX ... initialize -> callNextMethod -> .nextMethod -> validObject Execution halted/ *I also attached source code for the two related functions.* /expandX <- function(X, group) { incidence.mat <- incidenceMatrix(X, group) # group membership incidence matrix over.mat <- Matrix(incidence.mat %*% t(incidence.mat), sparse = TRUE, dimnames = dimnames(incidence.mat)) # overlap matrix grp.vec <- rep(1:nrow(over.mat), times = diag(over.mat)) # group index vector # expand X to X.latent X.latent <- NULL names <- NULL ## the following code will automatically remove variables not included in 'group' for(i in 1:nrow(incidence.mat)) { idx <- incidence.mat[i,]==1 X.latent <- cbind(X.latent, X[, idx, drop=FALSE]) names <- c(names, colnames(incidence.mat)[idx]) } colnames(X.latent) <- paste('grp', grp.vec, '_', names, sep = "") X.latent } incidenceMatrix <- function(X, group) { n <- nrow(X) p <- ncol(X) if (class(group) != 'list') { stop("Argument 'group' must be a list of integer indices or character names of variables!") } J <- length(group) grp.mat <- Matrix(0, nrow = J, ncol = p, dimnames=list(rep(NA, J), rep(NA, p))) if(is.null(colnames(X))) { colnames(X) <- paste("V", 1:ncol(X), sep="") } if (is.null(names(group))) { names(group) <- paste("grp", 1:J, sep="") } if (class(group[[1]]) == 'numeric') { for (i in 1:J) { ind <- group[[i]] grp.mat[i, ind] <- 1 colnames(grp.mat)[ind] <- colnames(X)[ind] } } else { ## character, names of variables for (i in 1:J) { grp.i <- as.character(group[[i]]) ind <- colnames(X) %in% grp.i grp.mat[i, ] <- 1*ind colnames(grp.mat)[ind] <- colnames(X)[ind] } } rownames(grp.mat) <- as.character(names(group)) # check grp.mat if (all(grp.mat == 0)) { stop("The names of variables in X don't match with names in group!") } grp.mat } / -- View this message in context: http://r.789695.n4.nabble.com/R-CRAN-check-works-great-on-local-Mac-OS-but-failed-on-Windows-win-builder-web-Why-tp4712179.html Sent from the R help mailing list archive at Nabble.com.