Skip to content
Back to formatted view

Raw Message

Message-ID: <CAJqKk21Mk_h7NQyhD8i-BOGtYZVv5JonX2wRpe5ynUmR+FLhKg@mail.gmail.com>
Date: 2025-08-10T16:29:33Z
From: Hernando Cortina
Subject: Including mode='wb' in download.file() for .xlsx files on Windows ?

Hello all, regarding download.file():

On Windows, if mode is not supplied (missing()) and url ends in one of
??.gz??, ??.bz2??, ??.xz??, ??.tgz??, ??.zip??, ??.jar??, ??.rda??,
??.rds??, ??.RData?? or ??.pdf??, mode = "wb" is set so that a binary
transfer is done to help unwary users.

May I suggest possibly including .xlsx files to the list of extensions
that get this treatment?

Downloading such files may be a quite common activity in the R
community and having to manually add mode=?wb? may indeed catch
Windows users unaware, particularly if they are coming from Linux or
Mac where this is not necessary.

I understand that it?s hard to know when to stop when adding
additional extensions.  That said, .xlsx is quite ubiquitous in the
wild and standardized under ECMA-376.

I hope this might be helpful to others, and thank you for your consideration.
Hernando
---------------

 The change in src/library/utils/R/Windows/download.file.R would be:

?

if(missing(mode) && length(grep("\\.(gz|bz2|xz|tgz|zip|jar|rd[as]|RData|xlsx)$",

                    URLdecode(url))))

        mode <- "wb"

?