【问题标题】:Probably a fairly trivial error in an R function在 R 函数中可能是一个相当微不足道的错误
【发布时间】:2013-11-23 19:33:18
【问题描述】:

我在控制台中粘贴以下函数:

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"

如果我通过逐行粘贴来执行函数的代码,那么一切都很好。这里出了什么问题 - 你能帮忙吗?我在这里想念的东西一定很明显。

【问题讨论】:

    标签: r function console copy-paste


    【解决方案1】:

    在 R 中,你必须写 return(...) - 包括括号应该可以解决你的问题。

    【讨论】:

    • 谢谢 - 这解决了它。
    • 或者,如果你在函数的末尾,你甚至不需要包含return
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-12
    • 1970-01-01
    • 2010-12-11
    • 1970-01-01
    相关资源
    最近更新 更多