运行CellChat教程调用identifyOverExpressedGenes遇closure类型复制错误
CellChat运行
identifyOverExpressedGenes时出现Error in rep(no, length.out = len)错误的解决方法 问题背景
运行CellChat教程的data_HumanSkin数据集,在"为细胞间通讯分析预处理表达数据"步骤前一切正常,但执行identifyOverExpressedGenes函数时触发错误:
Error in rep(no, length.out = len) : attempt to replicate an object of type 'closure'
数据库配置代码(执行正常)
# 设置配体-受体互作数据库 CellChatDB <- CellChatDB.human showDatabaseCategory(CellChatDB) dplyr::glimpse(CellChatDB$interaction) CellChatDB.use <- subsetDB(CellChatDB, search = "Secreted Signaling") cellchat@DB <- CellChatDB.use
出错的预处理代码
# 为细胞间通讯分析预处理表达数据 cellchat <- subsetData(cellchat) if (future::supportsMulticore()) future::plan(future::multiprocess) if (future::supportsMulticore() == FALSE) future::plan(future::multisession) future::plan("multisession") cellchat <- identifyOverExpressedGenes(cellchat) cellchat <- identifyOverExpressedInteractions(cellchat)
可能的解决方向
修复并行配置冲突:连续调用两次
future::plan会覆盖之前的判断逻辑,导致并行环境初始化异常。简化并行配置代码:# 统一设置并行计划 if (future::supportsMulticore()) { future::plan(future::multiprocess) } else { future::plan(future::multisession) }避免重复调用
future::plan,防止环境状态混乱。检查
cellchat对象完整性:执行subsetData(cellchat)后,用str(cellchat)查看对象结构,确认@data、@idents等关键槽位无缺失或异常的闭包(closure)类型数据。更新CellChat到最新版:旧版本CellChat在并行模式下处理
identifyOverExpressedGenes可能存在bug,更新到稳定版:devtools::install_github("sqjin/CellChat")临时禁用并行运行:先关闭并行模式验证是否是并行环境导致的问题:
future::plan(future::sequential) cellchat <- identifyOverExpressedGenes(cellchat)若能正常运行,再逐步排查并行配置的细节问题。
内容的提问来源于stack exchange,提问作者Elaina Sculley
相关产品推荐
相关产品推荐

