Probably a fairly trivial error in an R function

霸气de小男生 提交于 2019-12-11 14:51:30

问题


I am pasting in the console the following function:

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))
}

And I am getting an error message:

> 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"

If I execute the code of the function by pasting line by line than everything is fine. What is going wrong here - can you help? It must be something fairly obvious that I am missing here.


回答1:


In R, you have to write return(...) - including the parentheses should fix your problem.



来源:https://stackoverflow.com/questions/20166895/probably-a-fairly-trivial-error-in-an-r-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!