Question: Problem In running read.Table function in R
0
gravatar for Vinay Singh
3.4 years ago by
Vinay Singh40
INDIA, New Delhi, JNU
Vinay Singh40 wrote:

I am reading a text file containing a table so I have used read.table function in R and getting the problem.

Error in FUN(left) : invalid argument type

This is the command I have used for reading table.

data = read.table("intensity.txt", header=T, stringsAsFactors=F)

The format of text file is as (Intensity value)

 control.drought  control.heat  drought.control  control.combined 
1 -0.5817744498 -10.0890279047 0.5817744498 -11.0284839686
2 -0.3181022766 -9.0243890594 0.3181022766 -10.2859574516
3 -0.2690112456 -8.0796832998 0.2690112456 -9.0171546861
4 -0.1847218231 -3.7873259884 0.1847218231 -4.3059746476
5 -0.2024207047 -3.8210416657 0.2024207047 -4.3258501175
6 -0.6141010588 -4.4140746914 0.6141010588 -5.0397997135
7 -2.2505578122 -10.1398011434 2.2505578122 -10.1410584892
8 -0.3309324672 -4.0731881207 0.3309324672 -4.238998183
9 -0.4096105152 -3.8298292653 0.4096105152 -4.0147223178
10  -0.0036240574 -2.8959797594 0.0036240574 -3.0966125001
data microarray analysis R • 4.5k views
ADD COMMENTlink modified 10 months ago by RamRS22k • written 3.4 years ago by Vinay Singh40
2

There is no probable reason, that you should have this error. Try labelling the first column (rowname/serial numbercol) with a name and read again?

ADD REPLYlink modified 10 months ago by RamRS22k • written 3.4 years ago by Sukhdeep Singh9.8k
1

Can't reproduce the error. Upload sample data if still you are in trouble.

ADD REPLYlink modified 10 months ago by RamRS22k • written 3.4 years ago by Tanvir Ahamed 270
1

I believe it will not be produced if you are trying to reproduce it in vi editor or nano, if you try to do it local machine with any text editor sometimes the file encoding changes. Probably the OP was trying to use text editor in local machine rather than in terminal and then run R locally in their machine. I did not have any problems when I ran it in through terminal while it was reproducible when I simply copied the data and pasted in the .txt file, only to find out that the file had different encoding and that the local R was unable to figure that out so the error. If you edit the .txt file to standard encoding it works of ask the local R to recognize it as the standard encoding.

ADD REPLYlink modified 10 months ago by RamRS22k • written 3.4 years ago by ivivek_ngs4.8k

Thanks @ Sukhdeep, BioM, vchris_ngs for your valuable time.

I have tried as suggested by vchris_ngs but still getting the same error as before.

ADD REPLYlink modified 3.4 years ago • written 3.4 years ago by Vinay Singh40
2

Can you share the file with us (dropbox/drive/gist)? and in R type : sessionInfo() and paste the output here.

ADD REPLYlink modified 10 months ago by RamRS22k • written 3.4 years ago by Sukhdeep Singh9.8k
1

Can you tell me what is the fileEncoding of your "intensity.txt", I checked it again. I just copied the data from your question and pasted in a text editor and checked the fileEncoding to UTF-8 and it simply working with the below commands. It is only the problem of encoding. If you are worknig on mac then use text wrangler to see the fileEncoding else see notepad++ for windows. This happens if you use mostly excel or convert a file from one format to another by simply copy pasting its contents and changing the extensions. So just open the .txt in any of the above above mentioned text editor to do the needful and use any of the below commands

I just put the data in this way

number  control.drought    control.heat    drought.control  control.combined
1       -0.58177445        -10.0890279     0.58177445       -11.02848397
2       -0.318102277       -9.024389059    0.318102277      -10.28595745
3       -0.269011246       -8.0796833      0.269011246      -9.017154686
4       -0.184721823       -3.787325988    0.184721823      -4.305974648
5       -0.202420705       -3.821041666    0.202420705      -4.325850118
6       -0.614101059       -4.414074691    0.614101059      -5.039799714
7       -2.250557812       -10.13980114    2.250557812      -10.14105849
8       -0.330932467       -4.073188121    0.330932467      -4.238998183
9       -0.409610515       -3.829829265    0.409610515      -4.014722318
10      -0.003624057       -2.895979759    0.003624057      -3.0966125

 

data<-read.delim("/path/test1.txt",sep="\t",header=T,stringsAsFactors=F, fileEncoding ="UTF-8")
data<-read.table("/path/test1.txt",sep="\t",header=T,stringsAsFactors=F, fileEncoding ="UTF-8")
ADD REPLYlink modified 10 months ago by RamRS22k • written 3.4 years ago by ivivek_ngs4.8k

Thanks you all I have started another session of R and now its working fine.

But here comes the new problem

data = read.table("Intensity.txt", header=T, stringsAsFactors=F)
data1 <-as.matrix(data)
heatmap(as.matrix(data1))

Error in heatmap(as.matrix(data1)) : 'x' must be a numeric matrix

Please help me solve this problem.

ADD REPLYlink modified 10 months ago by RamRS22k • written 3.4 years ago by Vinay Singh40

Thanks all for helping me in getting the results.

Finally I got heat map of DE genes in a microarray experiment.

ADD REPLYlink modified 10 months ago by RamRS22k • written 3.4 years ago by Vinay Singh40
3
gravatar for ivivek_ngs
3.4 years ago by
ivivek_ngs4.8k
Seattle,WA, USA
ivivek_ngs4.8k wrote:

It is a problem of the fileEncoding . So open the .txt file in notepad or any text editor to change the file-encoding to any standard version like UTF-8 then it should work. This is the reason you are having the problem.

ADD COMMENTlink modified 10 months ago by RamRS22k • written 3.4 years ago by ivivek_ngs4.8k
2
gravatar for Antonio R. Franco
3.4 years ago by
Spain. Universidad de Córdoba
Antonio R. Franco4.1k wrote:

RUN a

sapply(data1, class)

to check the classes of your data. This way you will know whether your data are numeric or character

ADD COMMENTlink modified 10 months ago by RamRS22k • written 3.4 years ago by Antonio R. Franco4.1k

Thanks Antonio for your help,

*Yes it is showing Character, now how can i change it to numeric? *

 -0.581774450  -0.318102277  -0.269011246  -0.184721823  -0.202420705
  "character"   "character"   "character"   "character"   "character"
 -0.614101059  -2.250557812  -0.330932467  -0.409610515  -0.003624057
  "character"   "character"   "character"   "character"   "character"
   -10.089028     -9.024389     -8.079683     -3.787326     -3.821042
  "character"   "character"   "character"   "character"   "character"
    -4.414075    -10.139801     -4.073188     -3.829829     -2.895980
  "character"   "character"   "character"   "character"   "character"
  0.581774450   0.318102277   0.269011246   0.184721823   0.202420705
  "character"   "character"   "character"   "character"   "character"
  0.614101059   2.250557812   0.330932467   0.409610515   0.003624057
  "character"   "character"   "character"   "character"   "character"
   -11.028484    -10.285957     -9.017155     -4.305975     -4.325850
  "character"   "character"   "character"   "character"   "character"
    -5.039800    -10.141058     -4.238998     -4.014722     -3.096613
ADD REPLYlink modified 10 months ago by RamRS22k • written 3.4 years ago by Vinay Singh40

Now you can see the source of the error. Your numeric values are character

You have several choices

  1. In the code of read.table include this option as.is = TRUE

    I think this will be enough fot this time and for future use of the read.table() function

  2. Or in this case, after reading the table or at the time of creating the matrix include a as.numeric()

    data1 <-as.matrix(as.numeric(data))
    

After that, run a sapply(your_data, class) again to check if everything is OK

ADD REPLYlink modified 10 months ago by RamRS22k • written 3.4 years ago by Antonio R. Franco4.1k

Probably the reason why all the columns are characters is because one or more rows contain some non-numeric values. I would search the files for empty lines or comments. Another way to identify the faulty lines is to search of NAs in the data1 matrix.

ADD REPLYlink modified 10 months ago by RamRS22k • written 3.4 years ago by Giovanni M Dall'Olio26k

I have used this script to change the data into numeric data

data.frame(lapply(data1,as.numeric))

but now getting other error,

heatmap(as.matrix(data.frame))
Error in as.vector(x, mode) :

cannot coerce type 'closure' to vector of type 'any'

If any one can help me in getting desired results, it would be a great help.

ADD REPLYlink modified 10 months ago by RamRS22k • written 3.4 years ago by Vinay Singh40

Some heatmaps works only with matrix, not data.frame

Give it a try

ADD REPLYlink modified 10 months ago by RamRS22k • written 3.4 years ago by Antonio R. Franco4.1k
1
gravatar for Mo
3.4 years ago by
Mo890
/
Mo890 wrote:

I load your data without any problem

data <- read.table("path to your data /data.txt", header=TRUE, quote="\"")

#  control.drought control.heat drought.control control.combined
#1     -0.581774450   -10.089028     0.581774450       -11.028484
#2     -0.318102277    -9.024389     0.318102277       -10.285957
#3     -0.269011246    -8.079683     0.269011246        -9.017155
#4     -0.184721823    -3.787326     0.184721823        -4.305975
#5     -0.202420705    -3.821042     0.202420705        -4.325850
#6     -0.614101059    -4.414075     0.614101059        -5.039800
#7     -2.250557812   -10.139801     2.250557812       -10.141058
#8     -0.330932467    -4.073188     0.330932467        -4.238998
#9     -0.409610515    -3.829829     0.409610515        -4.014722
#10    -0.003624057    -2.895980     0.003624057        -3.096613
ADD COMMENTlink modified 10 months ago by RamRS22k • written 3.4 years ago by Mo890
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 526 users visited in the last hour