Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recoverable file deletion in R

Tags:

r

According to these questions:

  1. Automatically Delete Files/Folders
  2. how to delete a file with R?

the two ways to delete files in R are file.remove and unlink. These are both permanent and non-recoverable.

Is there an alternative method to delete files so they end up in the trash / recycle bin?

like image 782
duncanrager Avatar asked Oct 15 '22 13:10

duncanrager


1 Answers

I wouldn't know about a solution that is fully compatible with Windows' "recycle bin", but if you're looking for something that doesn't quite delete files, but prevents them from being stored indefinitely, a possible solution would be to move files to the temporary folder for the current session.

The command tempdir() will give the location of the temporary folder, and you can just move files there - to move files, use file.rename().

They will remain available for as long as the current session is running, and will automatically be deleted afterwards . This is less persistent than the classic recycle bin, but if that's what you're looking for, you probably just want to move files to a different folder and delete it completely when you're done.

For a slightly more consistent syntax, you can use the fs package (https://github.com/r-lib/fs), and its fs::path_temp() and fs::file_move().

like image 83
giocomai Avatar answered Nov 02 '22 23:11

giocomai