file_ext
File Utilities
Description
Some file utilities
Usage
file_ext(x)
file_path_as_absolute(x)
file_path_sans_ext(x, compression = FALSE)
list_files_with_exts(dir, exts, all.files = FALSE, full.names = TRUE)
list_files_with_type(dir, type, all.files = FALSE, full.names = TRUE,
    OS_subdirs = .OStype())
Arguments
  
| x | a character vector specifying the file names or paths.  For file_path_as_absolute, 
only single string is supported at present. | 
  | compression | a logical value. If TRUE, the extensions "gz", "bz2" and "xz" will be 
trimmed before checking extensions. | 
  | dir | a character vector specifying the file directories. | 
  | exts | a character vector specifying the file extensions. | 
  
| all.files | a logical value.  If FALSE(the default), only visible (non-hidden) file 
or directory names are returned. Otherwise, the entire contents of 
directory are returned.  (Hidden files or directories are those with 
names that begin with a period.) | 
  | full.names | a logical value. If TRUE(the default), the directory path is prepended 
to the returned names.  Otherwise, only the file or directory name is 
in the return value. | 
  | type | a character string specifying the file type.  The supported file type could 
be code("code"), data("data"), demo("demo"), documentations("docs") 
and vignette("vignette").  See details as below. | 
  
  
| OS_subdirs | a character string specifying the OS-specific subdirectories when listing 
code and documentation files. See details as below. | 
 
Details
file_ext returns the file extensions (the letters and numbers after
the period in the base name of the file).
file_path_as_absolute turns a possibly relative file path absolute, 
performing tilde expansion if necessary. The file must exist.
file_path_sans_ext returns the file paths without extensions (and
without the period before the extension if there is an extension). 
Only purely alphanumeric extensions are recognized.  If compression 
is TRUE, the extensions "gz", "bz2" and "xz" will be trimmed (along with
the period preceding the compression extension) before checking extensions.
list_files_with_exts   returns the paths or names of the files in dir 
with extension in exts. Might be in a zipped directory on Windows.
list_files_with_type   returns a character vector with the paths of the files 
in 
dir of type 
type.  The supported type could be "code", "data", "demo", 
"docs" and "vignette".  All these types could be mapped to some groups of file extensions. 
 See following table:
| type | extensions | 
| "code" | "R", "r", "S", "s", "q" | 
| "data" | "R", "r", "RData", "rdata", "rda", "tab", "txt", "TXT", "tab.gz", 
        "txt.gz", "tab.bz2", "txt.bz2", "tab.xz", "txt.xz", "csv", 
        "CSV", "csv.gz", "csv.bz2", "csv.xz" | 
| "demo" | "R",  "r" | 
| "docs" | "Rd", "rd", "Rd.gz", "rd.gz" | 
| "vignette" | "Rnw", "rnw", "Snw", "snw", "Rtex","rtex", "Stex", "stex", "Rmd" | 
And then 
list_files_with_exts could be called to get the file paths. Additionally, 
when listing code(
type="code") and documentation(
type = "docs") files, 
files in OS-specific subdirectories are included (if present) according to the value 
of 
OS_subdirs. The default  
.OStype() is try to read system environment 
variable "R_OSTYPE". If this variable is not set, 
.Platform$OS.type is used indeed.  
Only file names leading with alphanumeric are valid for 
type = "code" or "docs" 
and only file names leading with alphabetic are valid for 
type = "demo".
 
Value
file_ext returns  a character vector representing the file extensions.
file_path_as_absolute returns a character string representing 
the absolute file path.
file_path_sans_ext   returns a character vector representing 
the file paths without extensions. 
list_files_with_exts  and list_files_with_type  return a 
character vector representing the paths or names of the files.
See Also
Examples
file_ext(c("fileA.txt", "fileB.png", "DESCRIPTION"))
file_path_sans_ext(c("fileC.csv", "fileD.csv.gz"))
file_path_sans_ext(c("fileC.csv", "fileD.csv.gz"), compress=TRUE)
## Not run: 
file_path_as_absolute(".")
list_files_with_exts(R.home("share/doc/html"), ext="css")
list_files_with_type(R.home("etc"), type="code")
## End(Not run)