R.utils icon indicating copy to clipboard operation
R.utils copied to clipboard

isGzipped return TRUE for non-existing file

Open xhdong-umd opened this issue 7 years ago • 2 comments

Running examples in compressFile:

cat(file="foo.txt", "Hello world!")
print(isGzipped("foo.txt"))
print(isGzipped("foo.txt.gz"))

Note the foo.txt.gz is not exist yet but isGzipped returned TRUE. Further test prove that it will return TRUE for any file name with gz even it doesn't exist.

isGzipped("test.gz")

> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.2

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] R.utils_2.5.0     R.oo_1.21.0       R.methodsS3_1.7.1

loaded via a namespace (and not attached):
 [1] htmlwidgets_0.8 magrittr_1.5    profvis_0.3.3   htmltools_0.3.5 tools_3.3.2     Rcpp_0.12.9     stringi_1.1.2  
 [8] knitr_1.15.1    stringr_1.2.0   digest_0.6.12  

xhdong-umd avatar Mar 01 '17 21:03 xhdong-umd

From the source code, looks like it is checking from file extension only sometimes. The function name and the help made me to expect the file at least need to be exist, or it should always check by content.

xhdong-umd avatar Mar 01 '17 21:03 xhdong-umd

Thanks for this. I've now clarified in the help that the file does indeed not need to exist (when `method = "extension"; the default).

I could look into the possibility of returning isFile(x) || .... However, that's major work, because it will require lots of rev dep checks. It could be that some code somewhere is relying on isGzipped() to test the filename extension regardless of the file existing or not.

HenrikBengtsson avatar Oct 19 '17 02:10 HenrikBengtsson