2
votes

I'm struggling with an R tutorial for the package MiRLAB although I'm not sure whether the problem is related to the package's function.

I want to use the function Pearson(), which only accepts .csv files. I've loaded a file perfectly but when I've tried the function Pearson() (the same happens with MI, IDA and Lasso), this error message appeared:

Error in read.table(file = file, header = header, sep = sep, quote = quote, : 'file' must be a character string or connection

dataset=read.csv("ArabPrueba1.csv", sep = ";")
cause= 3:23
effect= 24:44
pearson=Pearson(dataset,cause,effect)

Any idea on how can I change the file or the command line so it will be recognized by the function? Might it be a problem with the csv file or something else? In the example of the tutorial the file is directly taken from the package so this approach is not covered.

Thank you in advance

2
i think you should use: pearson=Pearson("ArabPrueba1.csv",cause,effect)cccmir
When I do so the error that appears is : Error in read.table(file = file, header = header, sep = sep, quote = quote, : more columns than column namesN.Ugartondo
try using a comma separated instead of semicoloncccmir
does your csv file has headers?cccmir
The ´read.csv` works fine with the semicolon, but somehow fails when using it in the function. I've also tried pearson = Pearson(read.csv("ArabPrueba1.csv", sep = ";"), cause, effect) but then, the error I get is Error in read.table(file = file, header = header, sep = sep, quote = quote, : 'file' must be a character string or connection.N.Ugartondo

2 Answers

1
votes

I've finally solved the problem, even if it doesn't seem a clean solution, it works. I guess the problem was that some extra "" were added to the original files when I took them to the console so I rewrite the files and re-added the recently created files to the console.

RNA <- read.table("RNA.csv", dec = ",", sep = ";", stringsAsFactors = FALSE, header = TRUE, blank.lines.skip = TRUE)
tRNA <- t(RNA)
write.table(tRNA, file = "tRNA_2.csv", quote = FALSE, dec = ".", sep = ",", qmethod = "escape")
tRNAt <- read.csv("tRNA_2.csv")

miRNA <- read.table("miRNA.csv", dec = ",", sep = ";", stringsAsFactors = FALSE, header = TRUE, blank.lines.skip = TRUE)
tmiRNA <- t(miRNA)
write.table(tmiRNA, file = "tmiRNAt.csv", quote = FALSE, dec = ".", sep = ",", qmethod = "escape")
tmiRNAt <- read.csv("tmiRNAt.csv")

dataset <- cbind2(x=tmiRNAt, y = tRNAt)
write.table(dataset, file = "dataset_2.csv", quote = FALSE, dec = ".", sep = ",", qmethod = "escape")

# MiRLAB:
library(miRLAB)
cause = 1:278
effect = 279:length(dataset)
ps = Pearson("dataset_2.csv", cause = cause, effect = effect)

I know it's not a good idea to write and read so many times but it's actually the way that it have worked better (worked at all).

Thank you for your help!

0
votes

here is an example:

# working:
# create csv file with "," seprator
write.table(x = mtcars, file = "data.csv", sep = ",", row.names = F)
Pearson(datacsv = "data.csv", cause = 2:3, effect = 3:4)

#           cyl      disp
#disp 0.9020329 1.0000000
#hp   0.8324475 0.7909486


# not work:
# create csv file with ";" seprator
write.table(x = mtcars, file = "data1.csv", sep = " ; ", row.names = F, col.names = F)
Pearson(datacsv = "data1.csv", cause = 2:3, effect = 3:4)

the inner read.csv uses default seprator "," just change your file and replace all semicolon with comma