'RMarkdown: "Error: path for html_dependency not found:"

I am a Chemist who uses R and R Studio to analyze mass spectrometry data. I have automated scripts that process my data, because there are a lot of files. The scripts call rmarkdown using render() to import data, manipulate the data frame, save the processed data frame as a .csv and generate an html of plots. I have a problem rendering rmarkdown files since I recently updated to R v3.5.1 and R Studio v1.1.463. The error I receive is: Error: path for html_dependency not found: which I get if I use the knit button in R Studio, or if I use render(). The script inside the rmarkdown runs to completion, as the resulting objects are present in the environment window in R Studio, but the html file doesn’t render, and I get the error which stops the loop of render() I use to process all the files in a specific folder. This is a process I have done many times before updating.

I ran traceback() and got the following results:

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

I have uninstalled and reinstalled packages several times. I even removed my library folder entirely once, then reinstalled. My packages are up to date, but I had problems installing packages since the update, including rmarkdown. I had to use install.packages(“package”, type=”binary”) to install the dependencies for rmarkdown in order to get it to install. Normally I can just use the Install button in R Studio.

This is a work PC (Windows 10, 64 bit) I do not have administrator access to. I have to uninstall/install through IT at my university, which is a hassle, so I want to come to them with a plan. My package library defaults to a network drive that I can read/write to, and I have limited access to the hard disks; either way I can’t seem to change where packages are installed in R Studio. I don’t know if I can re-install an older version of R and R Studio or if it would help. A lot of the packages I use are developed for the current version of R and I was having some other issues, which was why I updated in the first place. The exact same scripts and data files run properly on another PC (my personal laptop, which is also up to date on R, R Studio and packages); the only changes I made are to the working directory so the data loads properly. I also had no trouble installing packages.

Here is an example of my code; since my scripts are very long, complicated and data specific, I have prepared a more simplified version of what they do as an example. I really don’t think there is anything wrong with the scripts themselves, as I mentioned before I have run them many times before the update. I suspect something is wrong with either the install of R, R studio or rmarkdown.

The main script, which calls render() from rmarkdown:

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

The rmarkdown, named “Processing and QA Template.rmd” which is in "D:/Working Directory":

---
title: "Example Processing and QA"
author: "Matt Brege "
date: "2018-12-12"
output: html_document
params: 
  data: x
  path: x
---
```{r, echo=FALSE, message=FALSE}
library(dplyr)
library(ggplot2)
library(tidyr)

file_name <- substr(params$data, 1, nchar(params$data)-7)
folder <- params$path
input <- tbl_df(read.csv(paste0(file_name, "_MF.csv"), stringsAsFactors = FALSE)) 
```
```{r, echo=FALSE}
#...a series of long and complicated data manipulations later…
write.csv(input7, paste0("Output/", file_name, "_QAd.csv"), row.names=FALSE, na="")
```
```{r,r, echo=FALSE, warning=FALSE, message=FALSE}
#...plotting section…
# these are just examples
p1 <-ggplot(diamonds, aes(x=carat, y=price)) + geom_point()
print(p1)
p2<- ggplot(diamonds, aes(x=carat, y=price, color=clarity)) + geom_point()
print(p2)
p3<- ggplot(diamonds, aes(x=carat, y=price, color=cut)) + geom_point()
print(p3)
```

Finally, I have found the following similar posts about what appears to be the same issue, but they are old and from different versions of R, and it doesn’t seem like it was resolved in those instances anyway:

RMarkdown cannot knit: html_dependency not found

RNotebook cannot output due to html_dependency not found

R looks in the wrong place for html dependency

One suggestion from the last link was to clear the cache: “If you cached the chunk containing HTML widgets, you may need to invalidate the cache after you update R packages. – Yihui Xie Dec 6 '17 at 19:00” but I am not exactly sure what that means or how to do it. I generally run cat("\014") and rm(list=ls()) at the beginning of each script, but I don’t know if that’s what the suggestion means, and it has not helped.



Solution 1:[1]

I got it to work by:

  1. Clear Knitr Cashe... (see the little arrow next to the Knit-icon in RStudio).
  2. I also had to restart R (.rs.restartR() ).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman