Debian Codegraph @

man/mime_type.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/base64.R
3 \name{mime_type}
4 \alias{mime_type}
5 \title{Get the MIME types of files}
6 \usage{
7 mime_type(x, use_mime = loadable("mime"), empty = "text/plain")
8 }
9 \arguments{
10 \item{x}{A vector of file paths.}
11
12 \item{use_mime}{Whether to use the \pkg{mime} package.}
13
14 \item{empty}{The MIME type for files without extensions (e.g., \code{Makefile}).
15 If \code{NA}, the type will be obtained from system command. This argument is
16 used only for \code{use_mime = FALSE}.}
17 }
18 \value{
19 A character vector of MIME types.
20 }
21 \description{
22 If the \pkg{mime} package is installed, call \code{\link[mime:guess_type]{mime::guess_type()}}, otherwise
23 use the system command \code{file --mime-type} to obtain the MIME type of a file.
24 Typically, the \code{file} command exists on *nix. On Windows, the command should
25 exist if Cygwin or Rtools is installed. If it is not found, .NET's
26 \code{MimeMapping} class will be used instead (which requires the .NET framework).
27 }
28 \note{
29 When querying the MIME type via the system command, the result will be
30 cached to \code{xfun:::cache_dir()}. This will make future queries much faster,
31 since running the command in real time can be a little slow.
32 }
33 \examples{\dontshow{if (tolower(Sys.getenv('CI')) == 'true') \{}
34 f = list.files(R.home("doc"), full.names = TRUE)
35 mime_type(f)
36 mime_type(f, FALSE) # don't use mime
37 mime_type(f, FALSE, NA) # run command for files without extension
38 \dontshow{\}}
39 }