From 082673b28d479486c100e5715bb3c6f4b9e83126 Mon Sep 17 00:00:00 2001 From: James J Balamuta Date: Tue, 3 Sep 2024 23:44:01 -0700 Subject: [PATCH] Try first creating the temporary directory and, then, building the tempfile in the temporary directory with an extension. Delete the file when the function exits. --- R/surreal-text.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/R/surreal-text.R b/R/surreal-text.R index 723f95f..ccc6f6a 100644 --- a/R/surreal-text.R +++ b/R/surreal-text.R @@ -20,8 +20,12 @@ temporary_text_plot <- function(text, cex = 4) { # Replace empty spaces with double dots for better visibility # text <- gsub("", "..", text) - # Create a temporary file path - temp_file <- tempfile() + # Create a temporary file path using a known directory + temp_dir <- tempdir() + temp_file <- tempfile(tmpdir = temp_dir, fileext = ".ppm") + + # Ensure the temporary file is removed when the function exits + on.exit(unlink(temp_file)) # Create a bitmap image bitmap(temp_file, "ppm", height = 5, width = 5)