Learn R Programming

xfun (version 0.48)

mime_type: Get the MIME types of files

Description

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).

Usage

mime_type(x, use_mime = loadable("mime"), empty = "text/plain")

Value

A character vector of MIME types.

Arguments

x

A vector of file paths.

use_mime

Whether to use the mime package.

empty

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.

Examples

Run this code
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