fileUtilities: Useful utility functions for file/directory exploration and...

UtilityR Documentation

Useful utility functions for file/directory exploration and manipulation.

Description

Wrappers for dirname, file.choose, readLines. file.create, file.path to be called directly for listing directories, creating files, showing the files in a directory, and listing the content of files in a directory. fileCreate gives the functionality of file.choose(new=TRUE). filesList combines file.choose, dirname, and list.files to show the files in a directory, fileScan extends this and then returns the first few lines of each readable file

Usage

fileScan(f = NULL, nlines = 3, max = NULL, from = 1, filter = NULL)
filesList(f=NULL)
filesInfo(f=NULL,max=NULL)
fileCreate(newName="new.file")

Arguments

f

File path to use as base path (will use file.choose() if missing. If f is a directory, will list the files in that directory, if f is a file, will find the directory for that file and then list all of those files.)

nlines

How many lines to display

max

maximum number of files to display

from

First file (number) to display

filter

Just display files with "filter" in the name

newName

The name of the file to be created.

Details

Just a collection of simple wrappers to powerful core R functions. Allows the user more direct control of what directory to list, to create a file, or to display the content of files. The functions called include file.choose, file.path, file.info,file.create, dirname, and dir.exists. All of these are very powerful functions, but not easy to call interactively.

fileCreate will ask to locate a file using file.choose, set the directory to that location, and then prompt to create a file with the new.name. This is a workaround for file.choose(new=TRUE) which only works for Macs not using R.studio.

filesInfo will interactively search for a file and then list the information (size, date, ownership) of all the files in that directory.

filesList will interactively search for a file and then list all the files in same directory.

Note

Work arounds for core-R functions for interactive file manipulation

Author(s)

William Revelle

See Also

read.file to read in data from a file or read.clipboard from the clipboard. dfOrder to sort data.frames.

Examples



if(interactive()) {
#all of these require interactive input and thus are not given as examples

fileCreate("my.new.file.txt") 
filesList()   #show the items in the directory where a file is displayed
fileScan() #show the content of the files in a directory 
#or, if you have a file in mind
 f <- file.choose()  #go find it
filesList(f)
fileScan(f)
}


psychTools documentation built on May 29, 2024, 9:47 a.m.