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.
Related
I managed to successfully set up the 'ibmdbR' package today. The connection with my database works and I can also create ida.dataframes. Now I wanted to run the command 'idakmeans' but now I get this error all the time:
Error in idaKMeans(cars.ida, k = 3, maxiter = 5, distance = "euclidean") :
Function not available.
I have loaded the package before of course. Enclosed my code:
library(ibmdbR)
con <- idaConnect('bludb','admin','admin')
idaInit2(con)
cars<-scale(mtcars)
cars.ida <- as.ida.data.frame(as.data.frame(cars),'CARS')
m1 <- idaKMeans(cars.ida, k=3, maxiter=5, distance="euclidean")
How can I solve the problem?
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
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.
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.
I'm using JD Long's segue package (https://code.google.com/p/segue/) to do some parallel computing, and am running into an issue loading CRAN packages on the EC2 instances.
First, I created an EMR cluster like so:
myCluster <- createCluster(numInstances = 5,
cranPackages = c("RWeka", "tm"),
masterInstanceType="m1.large",
slaveInstanceType="m1.large",
location="us-east-1c",)
Per the documentation, I specified which packages I want to load (in this case, RWeka and tm).
The cluster seems to start properly, with no error messages. I am using RStudio on Linux Mint 17 with R version 3.0.2.
I wrote a function getTerms.jobAd which takes a character string and calls some functions from the packages above, and am using emrlapply() like so:
> jobAdTerms <- emrlapply(myCluster, X = as.list(jobAds[1:2, 3]), FUN = getTerms.jobAd)
RUNNING - 2014-06-24 17:05:19
RUNNING - 2014-06-24 17:05:50
WAITING - 2014-06-24 17:06:20
When I check the jobAdTerms list that is supposed to be returned, I get:
> jobAdTerms
[[1]]
[1] "error caught by Segue: Error in function (txt) : could not find function \"Corpus\"\n"
[[2]]
[1] "error caught by Segue: Error in function (txt) : could not find function \"Corpus\"\n"
Obviously, Corpus is one of the functions from the tm package.
What am I doing wrong? And how can I remedy this situation? Thanks!!
EDIT
Here's the function I am calling:
nGramTokenizer <- function(x) NGramTokenizer(x, Weka_control(min = 2, max = 4))
getTerms.jobAd <- function(txt) {
tmp <- tolower(txt)
tmp <- gsub('\\s*<.*?>|[:;,#$%^&*()?]|(?<=[a-zA-Z])\\.(?= |$)', '', tmp, perl = TRUE)
txt.Corpus <- Corpus(VectorSource(tmp))
txt.Corpus <- tm_map(txt.Corpus, stripWhitespace)
txt.TFV <- termFreq(txt.Corpus[[1]], control = list(dictionary = jobTags[, 1], wordLengths = c(1, Inf)))
txt.TFV2 <- termFreq(txt.Corpus[[1]], control = list(tokenize = nGramTokenizer, dictionary = jobTags[, 1], wordLengths = c(1, Inf)))
jobTerms <- rowSums(as.matrix(c(txt.TFV, txt.TFV2)))
return(jobTerms)
}
EDIT 2
Here's how you can reproduce the error:
data(crude)
jobAdTerms <- emrlapply(myCluster, X = as.list(crude), FUN = getTerms.jobAd)