downlit icon indicating copy to clipboard operation
downlit copied to clipboard

`downlit_md_path()` doesn't (necessarily?) write to `out_path`

Open jennybc opened this issue 1 year ago • 0 comments

I was playing with downlit_md_path() for possible use in reprex (https://github.com/tidyverse/reprex/issues/367) and noticed that I could not successfully use out_path. It does seem to work if one is doing everything below temp dir, as one might do in a test.

This reprex shows me working not below session temp dir and out_path is not honoured. (But I show that the downlit-ified file IS left is the session temp dir.)

Related to #41

library(downlit)

md_lines <- c(
  "``` r",
  "(x <- rnorm(3))",
  "#> [1] -0.3454356  1.2070087 -1.0364874",
  "mean(x)",
  "#> [1] -0.05830476",
  "```"
)

input_file <- "sly-fox.md"
brio::write_lines(md_lines, input_file)

file.exists(input_file)
#> [1] TRUE
brio::read_lines(input_file)
#> [1] "``` r"                                  
#> [2] "(x <- rnorm(3))"                        
#> [3] "#> [1] -0.3454356  1.2070087 -1.0364874"
#> [4] "mean(x)"                                
#> [5] "#> [1] -0.05830476"                     
#> [6] "```"

output_file <- "sly-fox-DOWNLIT.md"
file.exists(output_file)
#> [1] FALSE

retval <- downlit_md_path(input_file, out_path = output_file)
file.exists(output_file)
#> [1] FALSE
file.exists(retval)
#> [1] FALSE

fs::dir_ls(tempdir(), regexp = "sly-fox", recurse = TRUE)
#> /tmp/Rtmp9DYJsw/sly-fox-DOWNLIT.md

unlink(input_file)
unlink(output_file)

Created on 2022-08-17 with reprex v2.0.2.9000

jennybc avatar Aug 17 '22 15:08 jennybc