2

I use updated quarto and Rmarkdown and vtree ‘5.4.6’:

In the same project and same session:

Rmarkdown does what quarto does not: Rmarkdown renders vtree(iris, "Species") and quarto not (allthough quarto renders inline)

What could be the problem for this?

See here a reproducible example:

1. Rmarkdown

---
title: "test"
author: "Me"
date: '2022-06-18'
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(vtree)
```

## R Markdown

```{r cars}
vtree(iris, "Species")
```

enter image description here

2. Quarto

---
title: "Untitled"
format: html
editor: visual
---

## Quarto

```{r}
library(vtree)
vtree(iris, "Species")
```

When I click the Render button: -> it is NOT renderred: enter image description here

When I render inline: -> it is renderred: enter image description here

TarJae
  • 72,363
  • 6
  • 19
  • 66
  • 1
    Not able to reproduce your error though (tested on Mac) – akrun Jun 18 '22 at 18:21
  • 1
    Hmmhh. I will shut down everything and restart. – TarJae Jun 18 '22 at 18:22
  • 1
    I was using the same version for vtree. It may be an issue in your env as it relates to the path – akrun Jun 18 '22 at 18:22
  • I used `packageVersion('knitr')# [1] ‘1.39’` If it is not working, can you change `options(knitr.graphics.rel_path = TRUE)` – akrun Jun 18 '22 at 18:26
  • Now it says `Watching files for changes /xxxx/AppData/Local/Temp/RtmpkvBd5n/vtree001.png (404: Not Found)` – TarJae Jun 18 '22 at 19:44
  • 1
    Not sure as you are using windows – akrun Jun 19 '22 at 15:21
  • 1
    Many thanks Master anyway. It is like a black whole sometimes. I think I do something fundamental wrong. And I think it has to do with loading the data from extern device (database, USB stick), wrangling data, doing the analysis. That said, allthough all is in the global environment, when rendering there must be lack of access to the created dataframe. But never mind. I am sure I will solve this also. Still learning! Many thanks again for caring. You are definitely one of the shining lights of R programming commuinty for me! – TarJae Jun 19 '22 at 16:02
  • 1
    I believe this is an issue with vtree directly which does not support how Quarto is working. vtree function will write to file in a R session temp folder, which is persistent only for a R session. so it assumes that the knitting process happens in the same session as when the file is needed. With quarto, the conversion to HTML does not happen in R and the file saved have been removed when the R session used for knitting is closed. So I think this is a vtree package issue which does not write in the right place. I would open an issue there - you can tag me there if needed. – cderv Jun 20 '22 at 12:49
  • @cderv. Thank you very much for taking time and explaining. This is so helpful! – TarJae Jun 20 '22 at 14:46

2 Answers2

2

Quarto works a bit differently than R Markdown as it will run R only for the knitting process, and not for the conversion to output format, here HTML.

From the error message, vtree is writing to file the output in the R session temp folder. This folder is not persistent after the R session is closed, which happens once Quarto have run all the computation output. This means that the png file does not exists anymore when converting to HTML, hence the no image shown in HTML.

(regarding knitr warning, I believe it is knitr version matter, but that does not change the output).

Looking at vtree::vtree() function, it seems when knitting to HTML is detected R temp folder is used if none provided. IMO this should ne behave that way and it is an issue in vtree package.

To overcome the issue, you need to not let vtree do the default provide yourself a path. You can do that with folder argument. So this should work

---
title: "Untitled"
format: html
keep-md: true
---

## Quarto

```{r}
library(vtree)
if (!dir.exists("vtree_save")) dir.create("vtree_save")
vtree(iris, "Species", folder = "vtree_save")
```

I would report an issue in vtree repo about this behavior.

cderv
  • 6,272
  • 1
  • 21
  • 31
1

I am the author of the vtree package. I have just made a change to the code which I believe fixes the problem. See https://github.com/nbarrowman/vtree where there are instructions for downloading version 5.5.8 of the vtree package, which includes the fix.