[R-pkg-devel] creating indelible file during unit test

Tom Wainwright tcwainw at gmail.com
Tue Dec 12 18:42:41 CET 2017


In *nix systems, permission to delete is at the directory level, not the
file level, so you might try changing the mode of the parent directory,
rather than the file itself, as in:

> dir.create('test')
> > file.create(file.path("test",'file1'))
> [1] TRUE
> > Sys.chmod("test", mode="0000")
> > file.remove(file.path("test",'file1'))
> [1] FALSE
> Warning message:
> In file.remove(file.path("test", "file1")) :
>   cannot remove file 'test/file1', reason 'Permission denied'
> > Sys.chmod("test", mode="0777")
> > file.remove(file.path("test",'file1'))
> [1] TRUE
> >
>

Not sure if this will work in Windows, though.

Regards,
  Tom Wainwright

On Tue, Dec 12, 2017 at 4:24 AM, Thierry Onkelinx <thierry.onkelinx at inbo.be>
wrote:

> Dear all,
>
> Some function I wrote deletes a bunch of files. It is crucial that all
> files get deleted. Hence it should return an error when one or more
> files couldn't be deleted.
>
> I'm writing a unit test for this function. I fail to create a file
> that can't be deleted by the function. I've tried Sys.chmod(file,
> "000") which didn't work.
>
> Any suggestions?
>
> Best regards,
>
> ir. Thierry Onkelinx
> Statisticus / Statistician
>
> Vlaamse Overheid / Government of Flanders
> INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE
> AND FOREST
> Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
> thierry.onkelinx at inbo.be
> Kliniekstraat 25, B-1070 Brussel
> www.inbo.be
>
> ////////////////////////////////////////////////////////////
> ///////////////////////////////
> To call in the statistician after the experiment is done may be no
> more than asking him to perform a post-mortem examination: he may be
> able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
> The plural of anecdote is not data. ~ Roger Brinner
> The combination of some data and an aching desire for an answer does
> not ensure that a reasonable answer can be extracted from a given body
> of data. ~ John Tukey
> ////////////////////////////////////////////////////////////
> ///////////////////////////////
>
>
> Van 14 tot en met 19 december 2017 verhuizen we uit onze vestiging in
> Brussel naar het Herman Teirlinckgebouw op de site Thurn & Taxis.
> Vanaf dan ben je welkom op het nieuwe adres: Havenlaan 88 bus 73, 1000
> Brussel.
>
> ______________________________________________
> R-package-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>

	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list