2013-11-23 58 views
0

我粘貼在控制檯以下功能:大概在R功能的相當瑣碎的錯誤

mirna_counts <- function (wd) { 
mirna_ensemble <- read.table("/Volumes/Data/nimr/lewis/edgeR/mirna_ensemble.txt", header = 
TRUE, sep="\t") 
setwd(wd) 
all_counts <- read.table("accepted_hits_clean.count", sep="\t") 
colnames(all_counts) <- c("Ensembl.Gene.ID", "counts") 
mirna_clean_counts <- merge(x = mirna_ensemble, y = all_counts, by = "Ensembl.Gene.ID") 
write.csv(mirna_clean_counts, file="mirna_clean_counts.csv", row.names = FALSE) 
return c(sum(all_counts$counts), sum(mirna_clean_counts$counts)) 
} 

而且我收到一條錯誤消息:如果我執行的代碼

> mirna_counts <- function (wd) { 
+ mirna_ensemble <- read.table("/Volumes/Data/nimr/lewis/edgeR/mirna_ensemble.txt", header = TRUE, sep="\t") 
+ setwd(wd) 
+ all_counts <- read.table("accepted_hits_clean.count", sep="\t") 
+ colnames(all_counts) <- c("Ensembl.Gene.ID", "counts") 
+ mirna_clean_counts <- merge(x = mirna_ensemble, y = all_counts, by = "Ensembl.Gene.ID") 
+ write.csv(mirna_clean_counts, file="mirna_clean_counts.csv", row.names = FALSE) 
+ return c(sum(all_counts$counts), sum(mirna_clean_counts$counts))} 
Error: unexpected symbol in: 
"write.csv(mirna_clean_counts, file="mirna_clean_counts.csv", row.names = FALSE) 
return c" 

通過逐行粘貼的功能比一切都好。這裏出了什麼問題 - 你能幫忙嗎?這一定很明顯,我在這裏失蹤。

回答

3

在R中,您必須編寫return(...) - 包括括號可以解決您的問題。

+0

謝謝 - 這固定它。 – Nick

+1

另外,如果你在函數的結尾,你甚至不需要包含'return' – Dason