limma function error

limma做差异分析分步运行时候没有问题, 但是把步骤写成function时一直报错

limma_DEG <- function(expr,Class,control_pattern,case_pattern){
  group <- as.factor(Class)
  design <- model.matrix(~0+group)
  rownames(design) <- colnames(expr)
  colnames(design) <- levels(group)
  contrast.matrix<-makeContrasts(paste0(case_pattern,"-",control_pattern),levels = design)
  print(contrast.matrix)
  fit <- lmFit(expr,design)
  fit2 <- contrasts.fit(fit, contrast.matrix) 
  fit2 <- eBayes(fit2)  
  tempOutput = topTable(fit2, coef=1, n=Inf)
  nrDEG = na.omit(tempOutput) 
}
Error in paste0(case_pattern, "-", control_pattern) : 
  object 'case_pattern' not found 

一直以为是字符串传递的问题,最后发现是因为没有指定参数
更改

 contrast.matrix<-makeContrasts(contrasts = paste0(case_pattern,"-",control_pattern),levels = design)

你可能感兴趣的:(limma function error)