utils_file {pliman}R Documentation

Utilities for file manipulation

Description

Usage

file_extension(file)

file_name(file)

file_dir(file)

manipulate_files(
  pattern,
  dir = NULL,
  prefix = NULL,
  name = NULL,
  suffix = NULL,
  extension = NULL,
  sep = "",
  save_to = NULL,
  overwrite = FALSE,
  remove_original = FALSE,
  verbose = TRUE
)

pliman_indexes()

pliman_indexes_eq()

Arguments

file

The file name.

pattern

A file name pattern.

dir

The working directory containing the files to be manipulated. Defaults to the current working directory.

prefix, suffix

A prefix or suffix to be added in the new file names. Defaults to NULL (no prefix or suffix).

name

The name of the new files. Defaults to NULL (original names). name can be either a single value or a character vector of the same length as the number of files manipulated. If one value is informed, a sequential vector of names will be created as "name_1", "name_2", and so on.

extension

The new extension of the file. If not declared (default), the original extensions will be used.

sep

An optional separator. Defaults to "".

save_to

The directory to save the new files. Defaults to the current working directory. If the file name of a file is not changed, nothing will occur. If save_to refers to a subfolder in the current working directory, the files will be saved to the given folder. In case of the folder doesn't exist, it will be created. By default, the files will not be overwritten. Set overwrite = TRUE to overwrite the files.

overwrite

Overwrite the files? Defaults to FALSE.

remove_original

Remove original files after manipulation? defaults to FALSE. If TRUE the files in pattern will be removed.

verbose

If FALSE, the code is run silently.

Value

Examples


library(pliman)
# get file name, directory and extension
file <- "E:/my_folder/my_subfolder/image1.png"
file_dir(file)
file_name(file)
file_extension(file)

# manipulate files
dir <- tempdir()
list.files(dir)
file.create(paste0(dir, "/test.txt"))
list.files(dir)
manipulate_files("test",
                 dir = paste0(dir, "\\"),
                prefix = "chang_",
                save_to = paste0(dir, "\\"),
                overwrite = TRUE)
list.files(dir)


[Package pliman version 2.1.0 Index]