From ca87357da33d711e45d02fb28995b35d3e2e1a0e Mon Sep 17 00:00:00 2001 From: Taha Ahmed Date: Thu, 16 Feb 2012 21:41:43 +0100 Subject: [PATCH] Changed implementation to dirname(basename()). This should be more robust. ... This should be more robust as the dirname follows a more stringent format than the filename itself. --- ProvideSampleId.R | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ProvideSampleId.R b/ProvideSampleId.R index 24a9840..b3a9e99 100644 --- a/ProvideSampleId.R +++ b/ProvideSampleId.R @@ -3,7 +3,14 @@ ProvideSampleId <- function (pathexpfile) { # with a path to an experimental file. ## Note: the sample ID must derive directly from the file or path. - sampleid <- sub("\\.[\\w]+$", "", basename(pathexpfile), perl = TRUE) + # basename(dirname()) returns the name of the lowest sub-directory + # split()[[1]][2] splits the dirname at the hyphen and returns the sampleid + sampleid <- strsplit(x = basename(dirname(pathexpfile)), + split = "-")[[1]][2] + +# # basename() returns the filename sans path +# # sub() returns the filename sans extension +# sampleid <- sub("\\.[\\w]+$", "", basename(pathexpfile), perl = TRUE) #### The code below is the old ProvideSampleId() function # ### OBS! Only very rudimentary error-checking.