If the mime package is installed, call mime::guess_type()
, otherwise
use the system command file --mime-type
to obtain the MIME type of a file.
Typically, the file
command exists on *nix. On Windows, the command should
exist if Cygwin or Rtools is installed. If it is not found, .NET's
MimeMapping
class will be used instead (which requires the .NET framework).
mime_type(x, use_mime = loadable("mime"), empty = "text/plain")
A character vector of MIME types.
A vector of file paths.
Whether to use the mime package.
The MIME type for files without extensions (e.g., Makefile
).
If NA
, the type will be obtained from system command. This argument is
used only for use_mime = FALSE
.
if (FALSE) { # tolower(Sys.getenv("CI")) == "true"
f = list.files(R.home("doc"), full.names = TRUE)
mime_type(f)
mime_type(f, FALSE) # don't use mime
mime_type(f, FALSE, NA) # run command for files without extension
}
Run the code above in your browser using DataLab