Commit a0d24c8b by Eric Coissac

make doParallel optionnal and should solve the windows problem during CRAN checks

parent c4c6c590
...@@ -16,7 +16,6 @@ Imports: MASS, ...@@ -16,7 +16,6 @@ Imports: MASS,
Matrix, Matrix,
mvtnorm, mvtnorm,
stats, stats,
doParallel,
foreach, foreach,
Rdpack Rdpack
Suggests: knitr, Suggests: knitr,
...@@ -24,7 +23,8 @@ Suggests: knitr, ...@@ -24,7 +23,8 @@ Suggests: knitr,
roxygen2, roxygen2,
vegan, vegan,
testthat, testthat,
ade4 ade4,
doParallel
RdMacros: Rdpack RdMacros: Rdpack
Collate: Collate:
'internals.R' 'internals.R'
......
...@@ -38,7 +38,6 @@ export(simulate_correlation) ...@@ -38,7 +38,6 @@ export(simulate_correlation)
export(simulate_matrix) export(simulate_matrix)
export(varls) export(varls)
import(MASS) import(MASS)
import(doParallel)
import(foreach) import(foreach)
import(permute) import(permute)
import(stats) import(stats)
......
#' @include procmod.R #' @include procmod.R
#' @include procmod_frame.R #' @include procmod_frame.R
#' @include multivariate.R #' @include multivariate.R
#' @import doParallel
#' @import foreach #' @import foreach
#' @import stats #' @import stats
#' #'
...@@ -9,8 +8,8 @@ ...@@ -9,8 +8,8 @@
#' @author Eric Coissac #' @author Eric Coissac
NULL NULL
library(doParallel) .has_doParallel <- is.element("doParallel",installed.packages())
registerDoParallel(1) if (.has_doParallel) require(doParallel)
#' Compute the trace of a square matrix. #' Compute the trace of a square matrix.
#' #'
...@@ -193,10 +192,15 @@ varls <- function(..., ...@@ -193,10 +192,15 @@ varls <- function(...,
for (i in seq_len(nx)) for (i in seq_len(nx))
v_xs[[i]] <- var(xs[[i]]) v_xs[[i]] <- var(xs[[i]])
if (! getDoParRegistered()) registerDoParallel(1) if (.has_doParallel && getDoParRegistered()) {
`%dp%` <- `%dopar%`
}
else{
`%dp%` <- `%do%`
}
s_cov_xxs <- foreach(k = seq_len(nrand), s_cov_xxs <- foreach(k = seq_len(nrand),
.combine = cbind) %dopar% { .combine = cbind) %dp% {
s1_cov_xxs <- matrix(0, nrow = nx, ncol = nx) s1_cov_xxs <- matrix(0, nrow = nx, ncol = nx)
r_xs <- vector(mode = "list", nx) r_xs <- vector(mode = "list", nx)
r_ys <- vector(mode = "list", nx) r_ys <- vector(mode = "list", nx)
......
...@@ -61,10 +61,10 @@ simulate_matrix <- function(n, p, equal_var = TRUE) { ...@@ -61,10 +61,10 @@ simulate_matrix <- function(n, p, equal_var = TRUE) {
#' @return a numeric matrix of \code{nrow(reference)} rows and \code{p} columns #' @return a numeric matrix of \code{nrow(reference)} rows and \code{p} columns
#' #'
#' @examples #' @examples
#' sim1 <- simulate_matrix(15,5) #' sim1 <- simulate_matrix(25,10)
#' class(sim1) #' class(sim1)
#' dim(sim1) #' dim(sim1)
#' sim2 <- simulate_correlation(sim1,10,0.8) #' sim2 <- simulate_correlation(sim1,20,0.8)
#' corls(sim1, sim2)^2 #' corls(sim1, sim2)^2
#' #'
#' @author Eric Coissac #' @author Eric Coissac
......
...@@ -35,10 +35,10 @@ The intensity of the correlation is determined by the \code{r2} ...@@ -35,10 +35,10 @@ The intensity of the correlation is determined by the \code{r2}
parameter. parameter.
} }
\examples{ \examples{
sim1 <- simulate_matrix(15,5) sim1 <- simulate_matrix(25,10)
class(sim1) class(sim1)
dim(sim1) dim(sim1)
sim2 <- simulate_correlation(sim1,10,0.8) sim2 <- simulate_correlation(sim1,20,0.8)
corls(sim1, sim2)^2 corls(sim1, sim2)^2
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment