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.
In R, you have to write
return(...)
- including the parentheses should fix your problem.