This is the second time that I searched online for help with download.file and solved my problem by calling the mode argument but I don't know what is the reason or when/why to use them. Just saw the suggestion and passed the argument to get my problem solved.
The R help file on download.file() is a bit too brief and dose not tell me when to use particular mode
mode character. The mode with which to write the file. Useful values are "w", "wb" (binary), "a" (append) and "ab". Only used for the "internal" method. (See also ‘Details’.)
download.file(fileUrl, destfile = "./data/leekjpg.jpg", mode="wb")
This is what the docs say:
If mode is not supplied and url ends in one of .gz, .bz2, .xz, .tgz, .zip, .rda or .RData a binary transfer is done. Since Windows (unlike Unix-alikes) does distinguish between text and binary files, care is needed that other binary file types are transferred with mode = "wb". unix A progress bar tracks the transfer. If the file length is known, an equals sign represents 2% of the transfer completed: otherwise a dot represents 10Kb. Code written to download binary files must use mode = "wb", but the problems incurred by a text transfer will only be seen on Window
Basically it is saying that
"wb" are the same when using on Unix-like OS, because they do not differentiate between text and binary files, but Windows does.
In Windows the line endings are slightly different. To be safe I use "w" when opening text files, where as
"wb" when files are not supposed to be text, like