But I noticed that the diagram's resolution is really bad. This is because it exports to a PNG image insteaad of a PDF. Most diagrams I do export to PDF so their quality is really good, but DiagrammeR exports to PNG for some reason. How can I make it export to PDF?
This worked, thanks. But there is one problem. It only exports the PDF file, it doesn't include it in my PDF output. So I have to do it manually right after the code block:

Is there a way to
Automate it exporting to PDF so I don't have to do it every time and choose the file name every time