This is a test version of Biostars. For the public version, visit https://www.biostars.org.
-bash: ./HeatMap.R: cannot execute binary file. Why is this?

Hello everyone, I am trying to run an R script to generate a heat-map but I keep getting the following error. I have no idea what is wrong with my input file. My input looks like this:

      male   female   juvenile   egg   blastula
 Aub  13.3   34.1     2323       321   3231
 piwi   23     34        34           54      534 
 Ago  35     65         34           34      56
 Ago2 0       0           0            0         0

-bash: ./HeatMap.R: cannot execute binary file

my R script look like this.

#!/usr/bin/env Rscript
library("gplots")
Data <- read.csv("input.txt", sep = "\t", header = TRUE)
DataMatrix <- data.matrix(Data)
rownames(DataMatrix) <- c("Aub", "piwi", "Ago", "Ago2")
colnames(DataMatrix) <- c("male", "female", "juvenile", "egg", "blastula")
png('ZscorePlot.png')
DataMap <- heatmap.2(DataMatrix, trace="none", dendrogram ='none', Rowv = FALSE, Colv = FALSE, col = colorRamps::matlab.like2, key=TRUE, keysize=1.0, xlab = "Stage in Development", ylab = "RNAifactor")
dev.off()

Is there something wrong? by the way, this is not my original data, just a sample to show you how it looks like. thanks.

heatmapscript mapping rnaseq rpm
rownames(DataMatrix) <- c("Aub", "piwi", Ago")
----------------------------------------^

You're missing a double quote.

Thats me typing on here. its all good in my R script. I corrected that on the post. In my script its all good. But error persists

Why is your R script binary? Have you tried Rscripts myscripts.R? The cannot execute binary file typically has something with incompatible architectures.

to be honest I am not sure what you mean.

What does it return with the command file HeatMap.R?

it returns this,

-bash: ./HeatMap.R: cannot execute binary file

You ran

./Heatmap.R

Eric asked you to run

file Heatmap.R

file Heatmap.R gave the following and didnt generate anything in folder

HeatMap.R: data

I apologies for late response. I am limited to few post per certain hours.

The file utility tells you what kind of file Heatmap.R is, it does nothing else - that's expected. Think of it as a sanity check on the file. It is strange that you get data.

I think it should be Rscript file.R, not Rscripts.

Rscript Heatmap.R

gave this

Error: unexpected input in "book" Execution halted

sorry for late response, I am limited to ew posts

Of course. Now everybody knows I hardly run any R script. :D

I tried to execute the commands one at a time on command line and upon reaching

> rownames(DataMatrix) <- c("Bfl-Piwi-like1","Bfl-Piwi-like3","Bfl-Piwi-like2","Bfl-Piwi-like5","Bfl-Piwi-like4","Bfl-Ago1","Bfl-Ago-like","Bfl-Rdrp4","Bfl-Rdrp1","Bfl-Rdrp2","Bfl-Rdrp3","Bfl-Rdrp5","Bfl-Rdrp6","Bfl-Dro","Bfl-Dcr")

it gave the error

Error in dimnames(x) <- dn : 
  length of 'dimnames' [1] not equal to array extent

Your R script has errors then. Please fix them before trying to execute the script from the command line.

You shouldn't execute an Rscript with bash.

Please follow up on all your previous posts:

If an answer was helpful you should upvote it, if the answer resolved your question you should mark it as accepted.
Upvote|Bookmark|Accept

You need to run your file as:

$ Rscript HeatMap.R

You cannot run Rscripts with the R binary or with bash. Your shebang line should be taking care of this though.

What do you get for which -a Rscript?

which -a Rscript

/usr/local/bin/Rscript

2 answers

Column names are 5 and the number of columns are 6. The issue can be addressed by setting the first column as row names.

#!/usr/bin/env Rscript
library("gplots")
Data <- read.csv("input.tsv", sep = "\t", header = TRUE, row.names = 1) #first col as rownames
DataMatrix <- data.matrix(Data)
#rownames(DataMatrix) <- c("Aub", "piwi", "Ago", "Ago2") #Already set by row.names = 1
#colnames(DataMatrix) <- c("male", "female", "juvenile", "egg", "blastula") #Already set by header=TRUE
png('ZscorePlot.png')
DataMap <- heatmap.2(DataMatrix, trace="none", dendrogram ='none', Rowv = FALSE, Colv = FALSE, col = colorRamps::matlab.like2, key=TRUE, keysize=1.0, xlab = "Stage in Development", ylab = "RNAifactor")
dev.off()

Run using the Rscript command also make sure the data table is properly formatted.

input.tsv

        male    female  juvenile        egg     blastula
Aub     13.3    34.1    2323    321     3231
piwi    23      34      34      54      534
Ago     35      65      34      34      56
Ago2    0       0       0       0       0

this is the error after i run it

Attaching package: ‘gplots’

The following object is masked from ‘package:stats’:

    lowess

Error in make.names(col.names, unique = TRUE) : 
  invalid multibyte string at '<fe><ff>'
Calls: read.csv -> read.table -> make.names
In addition: Warning messages:
1: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  line 1 appears to contain embedded nulls
2: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  line 2 appears to contain embedded nulls
3: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  line 3 appears to contain embedded nulls
4: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  line 4 appears to contain embedded nulls
5: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  line 5 appears to contain embedded nulls
Execution halted

Hi,

I've updated the code there is no need to set rownames and colnames separately.Heatmap

I realized my Text file had a tab in the first row. removing the tab makes the code run without a problem. Thanks for all your help. I appreciate it.

I added code markup to your post for increased readability. You can do this by selecting the text and clicking the 101010 button. When you compose or edit a post that button is in your toolbar, see image below:

101010 Button

If an answer was helpful you should upvote it, if the answer resolved your question you should mark it as accepted.
Upvote|Bookmark|Accept

new text file that made the code work looks like this

name  male    female  juvenile        egg     blastula
Aub     13.3    34.1    2323    321     3231
piwi    23      34      34      54      534
Ago     35      65      34      34      56
Ago2    0       0       0       0       0

Sorry, why is this an answer? Please use comments unless you're answering the top level question.

I added correction to my initial text file. tab replaced with name.

why is this an answer?

That does not answer the above question. You should have edited your post and added this info there, not added it as an answer. Please edit and add now, and then delete this answer.

Log in to answer this question.