RMarkdown:“错误:未找到html_dependency的路径:“

dauxcl2d  于 2023-10-13  发布在  其他
关注(0)|答案(1)|浏览(93)

我是一名使用R和R Studio分析质谱数据的化学家。我有自动化的脚本来处理我的数据,因为有很多文件。这些脚本使用render()调用rmarkdown来导入数据、操作数据框、将处理后的数据框保存为.csv格式并生成html图。我最近更新到R v3.5.1和R Studio v1.1.463后,在渲染rmarkdown文件时遇到了问题。我收到的错误是:如果我在R Studio中使用knit按钮,或者如果我使用render(),就会得到Error: path for html_dependency not found:。rmarkdown中的脚本运行完成,因为结果对象出现在R Studio的环境窗口中,但是html文件没有呈现,我得到了错误,它停止了我用来处理特定文件夹中所有文件的render()循环。这是我在更新之前做过很多次的过程。
运行traceback(),得到以下结果:

  1. 8: stop("path for html_dependency not found: ", file, call. = FALSE)
  2. 7: FUN(X[[i]], ...)
  3. 6: lapply(dependencies, validate_html_dependency)
  4. 5: dependency_resolver(all_dependencies)
  5. 4: html_extras_for_document(knit_meta, runtime, dependency_resolver,
  6. format_deps)
  7. 3: base(...)
  8. 2: output_format$pre_processor(yaml_front_matter, utf8_input, runtime,
  9. knit_meta, files_dir, output_dir)
  10. 1: render("Processing and QA Template_INT_FINAL_MFAssignR.rmd",
  11. output_file = paste0(substr(file_list[i], 1, nchar(file_list[i]) -
  12. 4), ".html"), output_dir = folder, params = list(data = file_list[i], path = folder))

我已经重新安装了几次软件包。我甚至删除了我的图书馆文件夹完全一次,然后重新安装。我的软件包是最新的,但自从更新以来,我在安装软件包时遇到了问题,包括rmarkdown。我不得不使用install.packages(“package”, type=”binary”)来安装rmarkdown的依赖项,以便安装它。通常我可以在R Studio中使用Install按钮。
这是一台工作PC(Windows 10,64位),我没有管理员访问权限。我必须在我的大学通过IT卸载/安装,这是一个麻烦,所以我想带着一个计划来找他们。我的软件包库默认为一个网络驱动器,我可以读/写,我有有限的访问硬盘;无论哪种方式,我似乎都不能改变包在R Studio中的安装位置。我不知道我是否可以重新安装旧版本的R和R Studio,或者它是否会有帮助。我使用的很多包都是为当前版本的R开发的,我遇到了一些其他问题,这就是为什么我首先更新。完全相同的脚本和数据文件在另一台PC上正常运行(我的个人笔记本电脑,也是最新的R,R Studio和软件包);我所做的唯一更改是工作目录,以便数据正确加载。我安装软件包也没有问题。
这是我的代码的一个例子;由于我的脚本很长、很复杂,而且是数据专用的,我准备了一个更简化的版本作为示例。我真的不认为脚本本身有什么问题,就像我之前提到的,在更新之前我已经运行了很多次。我怀疑R、R Studio或rmarkdown的安装有问题。
主脚本从rmarkdown调用render()

  1. setwd("D:/Working Directory")
  2. library("rmarkdown")
  3. folder=paste0(getwd(),"/")
  4. file_list=list.files(path=folder, pattern="*_MF.csv")
  5. for (i in 1:length(file_list)){
  6. render("Processing and QA Template.rmd",
  7. output_file = paste0(substr(file_list[i],1, nchar(file_list[i])-4),".html"), output_dir = folder,
  8. params=list(data=file_list[i], path=folder))
  9. }

rmarkdown名为“Processing and QA Template.rmd”,位于“D:/Working Directory”中:

  1. ---
  2. title: "Example Processing and QA"
  3. author: "Matt Brege "
  4. date: "2018-12-12"
  5. output: html_document
  6. params:
  7. data: x
  8. path: x
  9. ---
  10. ```{r, echo=FALSE, message=FALSE}
  11. library(dplyr)
  12. library(ggplot2)
  13. library(tidyr)
  14. file_name <- substr(params$data, 1, nchar(params$data)-7)
  15. folder <- params$path
  16. input <- tbl_df(read.csv(paste0(file_name, "_MF.csv"), stringsAsFactors = FALSE))
  1. #...a series of long and complicated data manipulations later…
  2. write.csv(input7, paste0("Output/", file_name, "_QAd.csv"), row.names=FALSE, na="")
  1. #...plotting section…
  2. # these are just examples
  3. p1 <-ggplot(diamonds, aes(x=carat, y=price)) + geom_point()
  4. print(p1)
  5. p2<- ggplot(diamonds, aes(x=carat, y=price, color=clarity)) + geom_point()
  6. print(p2)
  7. p3<- ggplot(diamonds, aes(x=carat, y=price, color=cut)) + geom_point()
  8. print(p3)
  1. 最后,我发现以下类似的帖子似乎是同一个问题,但它们是旧的,来自不同版本的R,而且在这些情况下似乎没有解决:
  2. [RMarkdown cannot knit: html_dependency not found](https://stackoverflow.com/questions/47357536/rmarkdown-cannot-knit-html-dependency-not-found)
  3. [RNotebook cannot output due to html_dependency not found](https://stackoverflow.com/questions/44575160/rnotebook-cannot-output-due-to-html-dependency-not-found)
  4. [R looks in the wrong place for html dependency](https://stackoverflow.com/questions/47677303/r-looks-in-the-wrong-place-for-html-dependency)
  5. 最后一个链接中的一个建议是清除该高速缓存:* “如果你缓存了包含HTML小部件的块,你可能需要在更新R包后使该高速缓存无效。- Yihui Xie Dec 6 '17 at 19:00”* 但我不确定这意味着什么或如何做到这一点。我通常在每个脚本的开头运行`cat("\014")`和`rm(list=ls())`,但我不知道这是否是建议的意思,它没有帮助。
zfciruhq

zfciruhq1#

我让它工作了:

  1. Clear Knitr Cashe.(参见RStudio中Knit-icon旁边的小箭头)。
    1.我也不得不重新启动R(.rs.restartR())。

相关问题