What to do about this makePSOCKcluster error? - r

I'm running a function called mixedpower() that lets you simulate power at different sample sizes. However I get the following error and don't know how to handle it!
Error in makePSOCKcluster(names = spec, ...) :
Cluster setup failed. 11 of 11 workers failed to connect.
Here is a reproducible example. (Just to head off any comments, I know that gear shouldn't be a random variable here, but I'm just using it for the purpose of this example.)
#You can download the mixedpower package like this.
if (!require("devtools")) {
install.packages("devtools", dependencies = TRUE)}
devtools::install_github("DejanDraschkow/mixedpower")
library(mixedpower)
library(lme4)
m <- lmer(mpg ~ cyl + disp + hp + drat + (1|gear), data = mtcars)
mtcars$gear_num <- as.numeric(mtcars$gear)
power <- mixedpower(model = m, data = mtcars, fixed_effects = c("cyl", "disp", "hp", "drat"), simvar = "gear_num", steps = c(3, 4, 5), critical_value = 2)
And if it is helpful I am running RStudio version 1.1.453 on MacOS Mojave version 10.14.6.

I can't test but strongly suspect that your problem is related to a bug in recent versions of R (now patched in more recent versions). This issue describes a workaround of adding the following to your .Rprofile file (it's also possible that updating to the latest patched version of R would do it).
## WORKAROUND: https://github.com/rstudio/rstudio/issues/6692
## Revert to 'sequential' setup of PSOCK cluster in RStudio Console on macOS and R 4.0.0
if (Sys.getenv("RSTUDIO") == "1" && !nzchar(Sys.getenv("RSTUDIO_TERM")) &&
Sys.info()["sysname"] == "Darwin" && getRversion() >= "4.0.0") {
parallel:::setDefaultClusterOptions(setup_strategy = "sequential")
}

Related

Trouble getting H2O to work with Sparklyr

I am trying to get H2O working with Sparklyr on my spark cluster (yarn)
spark_version(sc) = 2.4.4
My spark cluster is running V2.4.4
According to this page the compatible version with my spark is 2.4.5 for Sparkling Water and the H2O release is rel-xu patch version 3. However when I install this version I am prompted to update my H2O install to the next release (REL-ZORN). Between the H2O guides and the sparklyr guides it's very confusing and contradictory at times.
Since this is a yarn deployment and not local, unfortunately I can't provide a repex to help with trobleshooting.
url <- "http://h2o-release.s3.amazonaws.com/sparkling-water/rel-2.4/5/sparkling-water-2.4.5.zip"
download.file(url = url,"sparkling-water-2.4.5.zip")
unzip("sparkling-water-2.4.5.zip")
# RUN THESE CMDs FROM THE TERMINAL
cd sparkling-water-2.4.5
bin/sparkling-shell --conf "spark.executor.memory=1g"
# RUN THESE FROM WITHIN RSTUDIO
install.packages("sparklyr")
library(sparklyr)
# REMOVE PRIOR INSTALLS OF H2O
detach("package:rsparkling", unload = TRUE)
if ("package:h2o" %in% search()) { detach("package:h2o", unload = TRUE) }
if (isNamespaceLoaded("h2o")){ unloadNamespace("h2o") }
remove.packages("h2o")
# INSTALLING REL-ZORN (3.36.0.3) WHICH IS REQUIRED FOR SPARKLING WATER 3.36.0.3
install.packages("h2o", type = "source", repos = "https://h2o-release.s3.amazonaws.com/h2o/rel-zorn/3/R")
# INSTALLING FROM S3 SINCE CRAN NO LONGER SUPPORTED
install.packages("rsparkling", type = "source", repos = "http://h2o-release.s3.amazonaws.com/sparkling-water/spark-2.4/3.36.0.3-1-2.4/R")
# AS PER THE GUIDE
options(rsparkling.sparklingwater.version = "2.4.5")
library(rsparkling)
# SPECIFY THE CONFIGURATION
config <- sparklyr::spark_config()
config[["spark.yarn.queue"]] <- "my_data_science_queue"
config[["sparklyr.backend.timeout"]] <- 36000
config[["spark.executor.cores"]] <- 32
config[["spark.driver.cores"]] <- 32
config[["spark.executor.memory"]] <- "40g"
config[["spark.executor.instances"]] <- 8
config[["sparklyr.shell.driver-memory"]] <- "16g"
config[["spark.default.parallelism"]] <- "8"
config[["spark.rpc.message.maxSize"]] <- "256"
# MAKE A SPARK CONNECTION
sc <- sparklyr::spark_connect(
master = "yarn",
spark_home = "/opt/mapr/spark/spark",
config = config,
log = "console",
version = "2.4.4"
)
When I try to establish a H2O context using the next chunk I get the following error
h2o_context(sc)
Error in h2o_context(sc) : could not find function "h2o_context"
Any pointers as to where I'm going wrong would be greatly appreciated.
See this tutorial please. The newer versions of Rsparkling use {H2OContext.getOrCreate(h2oConf)} instead of {h2o_context(sc)}.

could not find function "knnImputation" in R

I am getting error could not find function "knnImputation"
Rstudio version :- Version 1.2.1335
loaded packages :- c("ggplot2", "corrgram", "DMwR", "usdm", "caret", "randomForest", "e1071",
"DataCombine", "doSNOW", "inTrees", "rpart.plot", "rpart",'MASS','xgboost','stats')
I recommend using the VIM::kNN() imputation as the package DMwR has been removed from CRAN:
https://cran.r-project.org/web/packages/DMwR/index.html
# using DMwR::knnImputation
df_mod <- DMwR::knnImputation(df, k = 7)
# VIM approximate equivalent to DMwR
# Note, for numFun you can substitute stats::weighted.mean, they perform similarly, though some differences on the margins I am not sure of
df_mod <- VIM::kNN(df, k = 7, numFun = laeken::weightedMean, weightDist = TRUE)
I have had some challenges in some circumstances using DMwR::knnImputation, this appears to work well.

Error while Checking custom package " Error in library("PHit") : there is no package called 'PHit' "

I'm using Rcpp to convert a bunch of functions written in C++ into a R package and I've managed to get past all the bugs in the code, but when I run the check, all the code checks out, but when it loads my package "PHit" it gives me that error and halts Execution
This is Windows 10 and I'm using R 3.6 in R Studio. I'm building my package in my works Share drive so others have access if that makes a difference. I've tried reinstalling the package, I've checked the .libpaths() and every solution offered for every similar question. The packages in those questions were external such as dplyr
> pkgname <- "PHit"
> source(file.path(R.home("share"), "R", "examples-header.R"))
> options(warn = 1)
> options(pager = "console")
> base::assign(".ExTimings", "PHit-Ex.timings", pos = 'CheckExEnv')
> base::cat("name\tuser\tsystem\telapsed\n", file=base::get(".ExTimings", pos = 'CheckExEnv'))
> base::assign(".format_ptime",
+ function(x) {
+ if(!is.na(x[4L])) x[1L] <- x[1L] + x[4L]
+ if(!is.na(x[5L])) x[2L] <- x[2L] + x[5L]
+ options(OutDec = '.')
+ format(x[1L:3L], digits = 7L)
+ },
+ pos = 'CheckExEnv')
>
> ### * </HEADER>
> library('PHit')
Error in library("PHit") : there is no package called 'PHit'
Execution halted
I expect it to recognize the package because I can load it in the console just fine although it only contains one out of the several functions that should be available, if it completely compiled as it should

Error creating multiple heatmaps with ComplexHeatmap package

I am having difficulty with creating multiple heatmaps with the ComplexHeatmap package. When I run a script that contains code exactly lifted from the documentation (https://bioconductor.org/packages/release/bioc/vignettes/ComplexHeatmap/inst/doc/s3.a_list_of_heatmaps.html)...
library(ComplexHeatmap)
mat1 = matrix(rnorm(80, 2), 8, 10)
mat1 = rbind(mat1, matrix(rnorm(40, -2), 4, 10))
rownames(mat1) = paste0("R", 1:12)
colnames(mat1) = paste0("C", 1:10)
mat2 = matrix(rnorm(60, 2), 6, 10)
mat2 = rbind(mat2, matrix(rnorm(60, -2), 6, 10))
rownames(mat2) = paste0("R", 1:12)
colnames(mat2) = paste0("C", 1:10)
ht1 = Heatmap(mat1, name = "ht1")
ht2 = Heatmap(mat2, name = "ht2")
class(ht1)
class(ht2)
ht1 + ht2
... I get the error message:
Error in ht1 + ht2 : non-numeric argument to binary operator
Execution halted
I am running R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch" on Mac OS X 10.12.2 with ComplexHeatmap version 1.12.0. Thank you for any help!
I figured it out. The problem was that the "methods" package needs to be attached. If you run the above code directly in R (which I was NOT doing), it works as-is (becuase R apparently loads the methods package by default), but if you have the script in a file and run it via Rscript (which is what I WAS doing), you get the indicated error. However, If you add
library(methods)
to the top of the script, it works via Rscript.

Error while using transformation function in R

I was working with baby names data set and encountered below error while using transform function. Any guidance/suggestion would be highly appreciated. I did reinstalled the packages but of no avail.
Mac OS X (Mountain Lion)
R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet"
library(stringr)
require(stringr)
bnames1 <- transform(bnames1,
first = tolower(str_sub(name,1,1)),
last = tolower(str_sub(name,-1,1)),
vowels = vowels(name),
length= nchar(name),
per1000 = 10000 * prop,
one_par = 1/prop
)
Error in tolower(str_sub(name, 1, 1)) :
lazy-load database '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/stringr/R/stringr.rdb' is corrupt
In addition: Warning messages:
1: In tolower(str_sub(name, 1, 1)) :
restarting interrupted promise evaluation
2: In tolower(str_sub(name, 1, 1)) : internal error -3 in R_decompress1
internal error -3 is often a functioning of installing on top of a loaded package. Restart R and restart your application. There may be other issues, but until you do this you won't be going much further.
Try
remove.packages("stringr")
install.packages("stringr")

Resources