使用rentrez包时View()触发逻辑 coercion错误求助
错误:
is.na(output) || !is.character(output) 中出现 'length = 3' 强制转换为 'logical(1)' 错误提示
Error in is.na(output) || !is.character(output) : 'length = 3' in coercion to 'logical(1)'
触发错误的代码
library(rentrez) gene_sombols <- "IL7" organism <- "human" query <- paste(gene_sombols, organism, sep = " ") genes <- entrez_search(db="gene", term = query, retmax=1)
原本可正常运行的代码
genes <- entrez_search(db="gene", term = "IL7 human", retmax=1)
运行上述问题代码后,原本正常的代码也无法运行。
已完成的排查操作
- 加载旧工作空间时仍会触发错误
- 创建新工作空间无错误,已重新安装
rentrez包 - 删除原有代码重新编写,执行查询后点击查看结果触发错误,执行
traceback()和sessionInfo()得到以下输出:
traceback() 输出
> traceback() 10: .rs.explorer.objectDesc(.$object) 9: .rs.scalar(.rs.explorer.objectDesc(.$object)) 8: .rs.explorer.createInspectionResult(object, context, children) 7: .rs.explorer.inspectDefault(object, context) 6: .rs.explorer.inspectObject(object[[i]], childContext) 5: FUN(X[[i]], ...) 4: lapply(indices, function(i) { if (is.null(names) || !nzchar(names[[i]])) { name <- sprintf("[[%i]]", i) access <- sprintf("#[[%i]]", i) tags <- .rs.explorer.tags$VIRTUAL } else { name <- names[[i]] access <- sprintf("#[[\"%s\"]]", name) tags <- character() } childContext <- .rs.explorer.createChildContext(context, name, access, tags) .rs.explorer.inspectObject(object[[i]], childContext) }) 3: .rs.explorer.inspectList(object, context) 2: .rs.explorer.inspectObject(object, context) 1: .rs.rpc.explorer_begin_inspect("0e1396e2e86e48d88b07ab7585d76766", "resul")
sessionInfo() 输出
> sessionInfo() R version 4.3.1 (2023-06-16 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19044) Matrix products: default locale: [1] LC_COLLATE=German_Germany.utf8 LC_CTYPE=German_Germany.utf8 [3] LC_MONETARY=German_Germany.utf8 LC_NUMERIC=C [5] LC_TIME=German_Germany.utf8 time zone: Europe/Berlin tzcode source: internal attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] rentrez_1.2.3 loaded via a namespace (and not attached): [1] httr_1.4.7 compiler_4.3.1 R6_2.5.1 tools_4.3.1 curl_5.2.0 [6] jsonlite_1.8.8 XML_3.99-0.16.1
解决建议
- 避免使用RStudio的
View()函数查看entrez_search返回的对象,改用命令行方式查看:用str(resul)查看完整结构,或直接访问resul$ids、resul$esearchresult等具体元素 - 彻底清理旧工作空间,后续使用全新的工作环境运行代码,不要加载之前出错的工作空间文件
- 更新RStudio到最新版本,该错误由RStudio内置的对象探索器函数触发,新版本可能修复兼容性问题
- 如果需要可视化查看结果,可将查询返回的核心数据转换为数据框,比如执行
as.data.frame(resul$esearchresult)后再用View()查看
内容的提问来源于stack exchange,提问作者wbart
相关产品推荐
相关产品推荐

