Probably a fairly trivial error in an R function

2019-09-08 01:59发布

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条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-09-08 02:56

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

查看更多
登录 后发表回答