vincentarelbundock / tinytable

Simple and Customizable Tables in `R`
https://vincentarelbundock.github.io/tinytable
GNU General Public License v3.0
211 stars 18 forks source link

Failure when saving the output modifies the working directory #225

Closed etiennebacher closed 7 months ago

etiennebacher commented 7 months ago

Using the example from #224, you can see that when tinytable fails to save the output, it changes the working directory (also reproduced outside of reprex):

library(tinytable)

packageVersion("tinytable")
#> [1] '0.2.1.5'

dest <- tempfile(fileext = ".pdf")
getwd()
#> [1] "C:/Users/etienne/AppData/Local/Temp/Rtmpm4YATP/reprex-69447adb2d87-jolly-bass"

### No caption works fine

tt(mtcars) |> 
  save_tt(dest)

getwd()
#> [1] "C:/Users/etienne/AppData/Local/Temp/Rtmpm4YATP/reprex-69447adb2d87-jolly-bass"

### Adding a caption errors

tt(mtcars, caption = "foo") |> 
  save_tt(dest, overwrite = TRUE)
#> ! LaTeX Error: \caption outside float.
#> Error: LaTeX failed to compile idsg6917hhdr38jz0ceo3x.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See idsg6917hhdr38jz0ceo3x.log for more info.

getwd()
#> [1] "C:/Users/etienne/AppData/Local/Temp/Rtmp42tg4w"
vincentarelbundock commented 7 months ago

Thanks, good catch.

I believe that using on.exit() to reset the working directory will work in case of failure and success.

Should be fixed on Github now.

etiennebacher commented 7 months ago

Yes, I confirm. Thanks for the quick fix as always