installr icon indicating copy to clipboard operation
installr copied to clipboard

xlsx2csv grepl?

Open r2evans opened this issue 8 years ago • 2 comments

I'm intrigued by the xlsx2csv function ... never thought to use VB, very interesting.

I noticed that the line to check for an expected file name seemed odd, so I tested it out. (Use of cbind solely for quick/easy viewing.)

fn <- c("foo.xlsx", "foo.xls", "foo.xlsb", "foo.xlsm", "foo.xls.zip", "quux", "foo.docx")
cbind.data.frame(filename = fn, results = grepl("\\.xlsx || \\.xls", fn))
#      filename results
#1    foo.xlsx    TRUE
#2     foo.xls    TRUE
#3    foo.xlsb    TRUE
#4    foo.xlsm    TRUE
#5 foo.xls.zip    TRUE
#6        quux    TRUE
#7    foo.docx    TRUE

I don't think it's doing what you (I?) think it should. As an alternative, how about:

cbind.data.frame(filename = fn, results = grepl("\\.xls[xm]?$", fn) )
#      filename results
#1    foo.xlsx    TRUE
#2     foo.xls    TRUE
#3    foo.xlsb   FALSE
#4    foo.xlsm    TRUE
#5 foo.xls.zip   FALSE
#6        quux   FALSE
#7    foo.docx   FALSE

(I also suggest that .xlsm files should also work.)

r2evans avatar May 05 '16 05:05 r2evans