vincentarelbundock / tinytable

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

Mechanism to ignore warnings or remove log files? #260

Closed etiennebacher closed 3 months ago

etiennebacher commented 4 months ago

When the table is large and the output is "pdf" there is a warning because the table is truncated. As shown in #234, this can be solved with theme_tt("resize") but the fact that there's a warning also means that there's a .log file in the output directory. When several tables are generated like this, it creates a bunch of useless files.

library(tinytable)

# wide df
test <- cbind(mtcars[1, ], mtcars[1, ])

tt(test) |> 
  theme_tt("resize") |> 
  save_tt("foo.pdf")
#> Warning: Package tabularray Warning: Table width is too small, need 284.97998pt
#> more!

list.files(getwd())
#> [1] "foo.pdf"                    "hurt-puma_reprex.R"        
#> [3] "hurt-puma_reprex.spin.R"    "hurt-puma_reprex.spin.Rmd" 
#> [5] "ideyec26lr3vl8l7hv62yz.log"  #<<<<<<<<<<<<<<<<<<<< this one

I know this is quite low-priority, but it would nice to have a mechanism to automatically clean up the output directory at some point.

vincentarelbundock commented 4 months ago

Interesting. I wonder if there's a way to know what specific log files get created. I wouldn't want to delete a user's log files for other projects!

etiennebacher commented 4 months ago

I wouldn't want to delete a user's log files for other projects!

Hum, I hadn't thought about this. I see that you're using tinytex::xelatex(), maybe there's an arg that you can pass to engine_args of latexmk()? I have no clue about this, I don't even know where to look for in the LaTeX manual

vincentarelbundock commented 3 months ago

I looked into this a bit, but I can't find a way to catch the log file names easily. I guess I could capture output and parse, but that seems like a lot of work for a minor annoyance.

I understand it's not great, but realistically, I probably won't invest more time into this.

Would be happy to consider a proposed design or PR, of course.

etiennebacher commented 3 months ago

@vincentarelbundock could you reopen this? I understand it's low-priority but it's really annoying to have random .log files popping in the git pane (and I don't want to ignore all log files since I have some "useful" ones).

Maybe one solution would be to detect the difference in log files before and after running tinytex::xelatex(). For example, here:

https://github.com/vincentarelbundock/tinytable/blob/0a0b9d303e43a546359950d8ebeb33c850ba6333/R/save_tt.R#L95-L101

one could use:

existing_log_files <- list.files(wd, pattern = "\\.log$", full.names = TRUE)
tinytex::xelatex(f, pdf_file = output)

new_log_files <- setdiff(
    list.files(wd, pattern = "\\.log$", full.names = TRUE), 
    existing_log_files
)
# "remove_log_files " could be a function param
if (remove_log_files && length(new_log_files ) > 0) {
    invisible(file.remove(existing_log_files))
}
unlink(f)

What do you think about this?

I can make a PR if interested.

vincentarelbundock commented 3 months ago

Yep that sounds like a reasonable workaround. I'd be happy to merge something like that.