quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.89k stars 320 forks source link

Specific handling for custom writer lua file for R Markdown processing #4347

Open cderv opened 1 year ago

cderv commented 1 year ago

Adding figure creation in the test qmd file, we can see that the the figure dir is in another folder containing format in the name

And so now I have it all covered. Probably another issue but related.

The directory with format in the name is created by rmarkdown when R chunks are added. I don't think Quarto expect this so not sure we are cleaning this correctly.

When no output_file is passed to rmarkdown::render(), one is automatically determined considering the pandoc.to format.

# determine the output file for a pandoc conversion
pandoc_output_file <- function(input, pandoc_options) {
  to <- strsplit(pandoc_options$to, "[+-]")[[1]][[1]]
  ext <- pandoc_output_ext(pandoc_options$ext, to, input)
  output <- paste0(xfun::sans_ext(input), ext)
  basename(output)
}

With to being customwriter.lua, the output file will have a .customwriter suffix as we can see in above comments

Then the files where to store figures for knitr is computed based on output_file

files_dir_slash <- file.path(output_dir, knitr_files_dir(basename(output_file)))

which will lead to the other folder customwriter-yaml.customformat_files when R code are into this.

I believe this will happen with any format no known by rmarkdown function pandoc_output_ext

pandoc_output_ext <- function(ext, to, input) {
  if (!is.null(ext)) return(ext)
  if (to %in% c("latex", "beamer")) return(".pdf")
  if (to %in% c("html", "html4", "html5", "s5", "slidy", "slideous", "dzslides", "revealjs"))
    return(".html")
  if (to == "markdown" && tolower(xfun::file_ext(input)) != "md") return(".md")
  paste0(".", to)
}

I'll probably look into that in another issue too, but that explains the behavior and differences seen above

Originally posted by @cderv in https://github.com/quarto-dev/quarto-cli/issues/4260#issuecomment-1421667821

cderv commented 1 year ago

Real issue is that in R Markdown we are building the files dir with files_dir_slash <- file.path(output_dir, knitr_files_dir(basename(output_file)))

knitr_files_dir <- function(file) {
  paste(xfun::sans_ext(file), "_files", sep = "")
}

Combine with the above, as output_file would be input_name.customwriter.lua we remove only .lua when creating the directory. Which messes up what Quarto is looking for.