Missing make_comb_mat function in R UpSet plot library - r

I'm following the example on this site to format the data for the Upset plot:
https://jokergoo.github.io/ComplexHeatmap-reference/book/upset-plot.html
library(UpSetR)
set.seed(123)
lt = list(a = sample(letters, 5),
b = sample(letters, 10),
c = sample(letters, 15))
m1 = make_comb_mat(lt)
m1
The code fails at this line:
m1 = make_comb_mat(lt)
With the following error:
Error in make_comb_mat(lt) :
no se pudo encontrar la funciĆ³n "make_comb_mat"
(can't not find function "make_comb_mat")

The make_comb_mat() function is from the ComplexHeatmap package, which has implemented its own version of the upset function.
The ComplexHeatmap package is available on github: https://github.com/jokergoo/ComplexHeatmap

Related

Error in Z_aktuell * D : non-conformable arrays

Can anyone figure out why I get the error below after running the following code?
library(haven)
library(survival)
library(dplyr)
library(readr)
library(glmmLasso)
par(mar=c(1,1,1,1))
library(discSurv)
HH<- as.data.frame(read_dta("https://www.stata.com/data/jwooldridge/eacsap/recid.dta") )
HHC <- contToDisc(dataShort = HH, timeColumn = "durat", intervalLimits = 20,equi = TRUE)
dtLong<-dataLong(dataShort = HHC, timeColumn = "timeDisc",
eventColumn = "cens",timeAsFactor = FALSE)
formula.1<-y~factor(black)+factor(alcohol)
family<-binomial(link = "logit")
lambda <- 20
penal.vec<-20
next.try<-TRUE
BIC_vec<-rep(Inf,length(lambda))
Deltama.glm2<-as.matrix(t(rep(0,3)))#coefficients + Intercept
Smooth.glm2<-as.matrix(t(rep(0,20)))
j<-1;test.step<-1;
glm2 <- glmmLasso(formula.1,
rnd = NULL,family = family, data = dtLong, lambda=lambda[j],final.re=T,switch.NR=F,
control = list(smooth=list(formula=~- 1+as.numeric(timeInt),nbasis=20,spline.degree=3,
diff.ord=2,penal=penal.vec[test.step],start=Smooth.glm2[j,]),
method.final="EM", print.iter=T,print.iter.final=T,
eps.final=1e-4,epsilon=1e-4,complexity="non.zero",
start=Deltama.glm2[j,]))
Iteration 41
Final Re-estimation Iteration 9Error in Z_aktuell * D : non-conformable arrays
when I change Deltama.glm2<-as.matrix(t(rep(0,3))) to Deltama.glm2<-as.matrix(t(rep(0,2)))
I get the error
Iteration 1Error in grad.lasso[b.is.0] <- score.beta[b.is.0] - lambda.b * sign(score.beta[b.is.0]) :
NAs are not allowed in subscripted assignments
I have tried to remove the starting values as suggested on glmmLasso error and warning without success
Switching from R version 4.2.2 to 3.6.0 solved the issue. Seems there is a compatibility issue between glmmlasso and the newer versions of R.

Heatmap Plot -- Getting Error

I am looking at this link.
https://bioconductor.org/packages/devel/bioc/vignettes/ComplexHeatmap/inst/doc/s2.single_heatmap.html
This first several lines of code work fine, but now I'm getting this error.
Error in Heatmap(mat) : could not find function "Heatmap"
I'm no too familiar with R. Can someone tell me what is wrong here? Thanks.
Try running the following code:
source("https://bioconductor.org/biocLite.R")
if(!require(ComplexHeatmap)) biocLite("ComplexHeatmap")
if(!require(circlize)) install.packages('circlize')
# -------------------------------------------------------
library(ComplexHeatmap)
library(circlize)
set.seed(123)
mat = cbind(rbind(matrix(rnorm(16, -1), 4), matrix(rnorm(32, 1), 8)),
rbind(matrix(rnorm(24, 1), 4), matrix(rnorm(48, -1), 8)))
# permute the rows and columns
mat = mat[sample(nrow(mat), nrow(mat)), sample(ncol(mat), ncol(mat))]
rownames(mat) = paste0("R", 1:12)
colnames(mat) = paste0("C", 1:10)
Heatmap(mat)
Does this work for you?
If yes, your problem was that you had not installed the necessary packages before loading them with library. The first 3 lines of the code I provided is simply checking if you have installed the necessary packages, and then if not, it installs them.

Using .Fortran() from R package with error saying function not available

I tried the following codes:
library(quantreg) # to load the package
library(foreign) # to load the package
.Fortran("rqfn", PACKAGE = "quantreg")
but I get the following error:
Error in .Fortran("rqfn", PACKAGE = "quantreg") :
"rqfn" not available for .Fortran() for package "quantreg"
I have installed Rtools. But it does not solve the problem.
I also checked the issues concerning system paths (as in this site: https://github.com/stan-dev/rstan/wiki/Install-Rtools-for-Windows), but there is no problem about that.
Could anyone give me a hand? Thank you very much.
You can build your own library:
Download rqfn.f and rqfnb.f. The latter is needed for stepy method.
Call R CMD SHLIB rqfn.f rqfnb.f
use the function like this:
data(stackloss)
x <- stack.x
y <- stack.loss
n <- length(y)
p <- ncol(x)
dyn.load(paste0("rqfn", .Platform$dynlib.ext))
.Fortran("rqfn",
as.integer(n),
as.integer(p),
a = as.double(t(as.matrix(x))),
c = as.double(y),
rhs = double(p),
d = double(n),
beta = as.double(0.99995),
eps = as.double(1e-6),
tau = as.double(0.5),
wn = double(10 * n),
wp = double((p + 3) * p),
aa = double(p * p),
it.count = integer(2),
info = integer(1))

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 when using RColorBrewer to plot

I am trying to make a plot of a map from raster data. I am using this code:
library(raster)
library(rgdal)
library(classInt)
library(RColorBrewer)
NDII = raster("G:\\Sheyenne\\image_differencing\\NDII\\differenced.tif")
value.vector = values(NDII)
breaks.qt = classIntervals(value.vector, n = 6, style = "jenks", intervalClosure = "right")
print (plot(NDII, breaks=breaks.qt$brks, col = brewer.pal(6, "Set1")))
but this returns:
Error in print(plot(NDII, breaks = breaks.qt$brks, col = brewer.pal(6, :
error in evaluating the argument 'x' in selecting a method for function 'print': Error in .asRaster(x, col, breaks, zrange, colNA, alpha = alpha) :
could not find function "brewer.pal"
You provide no reproducible example, and I can't reproduce your error.
The following code, which is the same as yours using the reproducible example of the R logo as a raster (and with the shortcut of using NDII[] instead of storing values(NDII) in a variable) works just fine for me...
library(raster)
library(rgdal)
library(classInt)
library(RColorBrewer)
NDII = raster(system.file("external/rlogo.grd", package="raster"))
# next line is really slow, I'd advise to run crop(NDII, extent(0,20,0,20))
# before to make quick tests
breaks.qt = classIntervals(NDII[], n = 6, style = "jenks",
intervalClosure = "right")
plot(NDII, breaks=breaks.qt$brks, col = brewer.pal(6, "Set1"))
Do you reproduce your error with this code? Maybe you can start with a new, fresh session?

Resources