Last data update: 2014.03.03

R: Find a Prefix Based on Names of Existing Files
findPrefixR Documentation

Find a Prefix Based on Names of Existing Files

Description

Find the prefixes or suffixes of files with a given suffix or prefix in a directory.

Usage

findPrefix(suffix,path=".")
findSuffix(prefix,path=".")

Arguments

suffix

character vector of suffixes

prefix

character vector of prefixes

path

directory to look for files in

Details

The function findPrefix locates all files in a directory that end with one of the provided suffixes; where as findSuffix locates all files that start with the given prefixes.

Value

A character vector of all the prefixes or sufixes of files in the working directory that matched to one of the given suffixes.

Author(s)

Anisa Egeli, Vancouver Island University, Nanaimo BC

Examples

local(envir=.PBSmodEnv,expr={
  edir = system.file("examples", package="PBSmodelling")
  print(findPrefix(suffix=c(".txt", ".r"),path=edir)); cat("\n")

  #or use R's dir for similar functionality
  print(dir(pattern="txt$",path=edir)); cat("\n")
  print(dir(pattern="^[a-h]",path=edir)); cat("\n")
})

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(PBSmodelling)
Error in library(PBSmodelling) : 
  there is no package called 'PBSmodelling'
Execution halted