Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Temp files automatically deleted in R shiny app - Error in file: cannot open the connection

I created a R shiny app that automatically runs every day using a batch file. Everything works fine when lauching the app, but the next day it crashes and I get the following message:

Warning in file(open = "w+") :
  cannot open file
'C:\Users\bertin\AppData\Local\Temp\RtmpKiBPOU\Rf3f835d1a66' : No such file or directory
Warning: Error in file: cannot open the connection
  [No stack trace available]

Actually this issue is related to the tempdir() folder created by the R session executing the shiny app. This folder is automatically deleted after a certain time. Do I have to delete all Temp files on each refreshing? Or on the contrary is it needed to prevent R from deleting all shiny temp files on Temp folder? Thanks!


Edit - Here is how to intentionally generate the error:

tempdir()
dir.exists(tempdir())

library(shiny)

# Windows shell required
shinyApp(
    ui = fluidPage("Please reload to see me fail."),
    server = function(input, output) {
        shell(paste("rmdir", dQuote(
            normalizePath(tempdir(), winslash = "/", mustWork = FALSE), q = FALSE
        ), "/s /q"))
    }
)

result

like image 816
JeanBertin Avatar asked Nov 05 '18 10:11

JeanBertin


1 Answers

By now I've found a setting in Windows 10 (Storage Sense) concerning the deletion of temporary files, which seems to be active by default.

Navigate as follows and uncheck:

  1. Settings
  2. System Storage
  3. Storage Sense
  4. Change how we free up space automatically
  5. Delete temporary files that my apps aren't using

Windows Storage Sense

like image 197
ismirsehregal Avatar answered Oct 23 '22 10:10

ismirsehregal